[ActiveLock-Development] CVS: alcrypto/test Form1.frm,NONE,1.1 Module1.bas,NONE,1.1 Project1.vbp,NON
Brought to you by:
ialkan
From: Thanh H. T. <th...@us...> - 2003-07-28 01:06:51
|
Update of /cvsroot/activelock/alcrypto/test In directory sc8-pr-cvs1:/tmp/cvs-serv28956 Added Files: Form1.frm Module1.bas Project1.vbp Log Message: Test program for ALCrypto.Dll --- NEW FILE: Form1.frm --- VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4305 ClientLeft = 60 ClientTop = 345 ClientWidth = 7185 LinkTopic = "Form1" ScaleHeight = 4305 ScaleWidth = 7185 StartUpPosition = 3 'Windows Default Begin VB.TextBox txtSig Height = 855 Left = 1080 MultiLine = -1 'True TabIndex = 18 Top = 3120 Width = 4215 End Begin VB.CommandButton cmdVerify Caption = "&Verify" Height = 375 Left = 5640 TabIndex = 17 Top = 3360 Width = 1455 End Begin VB.CommandButton cmdSign Caption = "&Sign" Height = 375 Left = 5640 TabIndex = 15 Top = 3000 Width = 1455 End Begin VB.CommandButton cmdPubDec Caption = "Public Dencryp&t" Height = 375 Left = 5640 TabIndex = 14 Top = 2040 Width = 1455 End Begin VB.CommandButton cmdPrivEnc Caption = "&Private Encrypt" Height = 375 Left = 5640 TabIndex = 13 Top = 1680 Width = 1455 End Begin VB.CommandButton cmdDecrypt Caption = "Private &Decrypt" Height = 375 Left = 5640 TabIndex = 12 Top = 1320 Width = 1455 End Begin VB.CommandButton cmdEncrypt Caption = "Public &Encrypt" Height = 375 Left = 5640 TabIndex = 11 Top = 960 Width = 1455 End Begin VB.TextBox txtDecrypted Height = 615 Left = 1080 TabIndex = 10 Top = 2400 Width = 4215 End Begin VB.TextBox txtEncrypted Height = 615 Left = 1080 TabIndex = 8 Top = 1680 Width = 4215 End Begin VB.TextBox txtData Height = 615 Left = 1080 TabIndex = 6 Text = "Text1" Top = 960 Width = 4215 End Begin VB.CommandButton cmdGen Caption = "&Generate" Height = 375 Left = 5640 TabIndex = 4 Top = 120 Width = 1455 End Begin VB.TextBox txtPub Height = 375 Left = 1080 TabIndex = 3 Top = 480 Width = 4215 End Begin VB.TextBox txtPriv Height = 375 Left = 1080 TabIndex = 1 Top = 120 Width = 4215 End Begin VB.Label Label6 Caption = "Signature:" Height = 375 Left = 0 TabIndex = 16 Top = 3000 Width = 1095 End Begin VB.Label Label5 Caption = "Decrypted:" Height = 375 Left = 0 TabIndex = 9 Top = 2520 Width = 1095 End Begin VB.Label Label4 Caption = "Encrypted:" Height = 375 Left = 0 TabIndex = 7 Top = 1800 Width = 1095 End Begin VB.Label Label3 Caption = "Text:" Height = 375 Left = 0 TabIndex = 5 Top = 1080 Width = 1095 End Begin VB.Label Label2 Caption = "Public Key:" Height = 375 Left = 0 TabIndex = 2 Top = 480 Width = 1215 End Begin VB.Label Label1 Caption = "Private Key:" Height = 375 Left = 0 TabIndex = 0 Top = 120 Width = 1215 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim mstrEncrypted As String * 128 Private Sub cmdDecrypt_Click() Decrypt 1 End Sub Private Sub Decrypt(CryptType As Long) Screen.MousePointer = vbHourglass Dim key As RSAKey rsa_createkey txtPub, Len(txtPub), txtPriv, Len(txtPriv), key Dim strData As String * 128 strData = mstrEncrypted Dim nLen& nLen = Len(strData) rsa_decrypt CryptType, strData, nLen, key txtDecrypted = strData Screen.MousePointer = vbDefault End Sub Private Sub cmdEncrypt_Click() Encrypt 0 End Sub Private Sub Encrypt(CryptType As Long) Screen.MousePointer = vbHourglass Dim key As RSAKey rsa_createkey txtPub, Len(txtPub), txtPriv, Len(txtPriv), key mstrEncrypted = txtData Dim nLen& nLen = Len(txtData) rsa_encrypt CryptType, mstrEncrypted, nLen, key txtEncrypted = mstrEncrypted Screen.MousePointer = vbDefault End Sub Private Sub cmdPrivEnc_Click() Encrypt 1 End Sub Private Sub cmdPubDec_Click() Decrypt 0 End Sub Private Sub cmdGen_Click() Screen.MousePointer = vbHourglass Dim key As RSAKey Dim prog As ProgressType rsa_generate key, 1024, AddressOf ProgressUpdate, VarPtr(prog) Dim strBlob As String Dim blobLen As Long rsa_public_key_blob key, vbNullString, blobLen If blobLen > 0 Then strBlob = String(blobLen, 0) rsa_public_key_blob key, strBlob, blobLen Debug.Print "Public blob: " & strBlob txtPub = strBlob End If rsa_private_key_blob key, vbNullString, blobLen If blobLen > 0 Then strBlob = String(blobLen, 0) rsa_private_key_blob key, strBlob, blobLen Debug.Print "Private blob: " & strBlob txtPriv = strBlob End If Screen.MousePointer = vbDefault End Sub Private Sub cmdSign_Click() Screen.MousePointer = vbHourglass Dim key As RSAKey rsa_createkey txtPub, Len(txtPub), txtPriv, Len(txtPriv), key Dim nLen&, sLen& nLen = Len(txtData) rsa_sign key, txtData, nLen, vbNullString, sLen Dim strSig As String strSig = String(sLen, 0) rsa_sign key, txtData, nLen, strSig, sLen txtSig = modBase64.Base64_Encode(strSig) Screen.MousePointer = vbDefault End Sub Private Sub cmdVerify_Click() Screen.MousePointer = vbHourglass Dim key As RSAKey Dim strSig As String strSig = modBase64.Base64_Decode(txtSig) rsa_createkey txtPub, Len(txtPub), txtPriv, Len(txtPriv), key If rsa_verifysig(key, strSig, Len(strSig), txtData, Len(txtData)) = 0 Then MsgBox "Signature verification passed!" Else MsgBox "Signature verification failed!" End If Screen.MousePointer = vbDefault End Sub --- NEW FILE: Module1.bas --- Attribute VB_Name = "Module1" Option Explicit Option Base 0 Type RSAKey ' 36-byte structure bits As Long ' bytes As Long ' modulus As Integer ' exponent As Integer ' private_exponent As Integer ' p As Integer ' q As Integer ' iqmp As Integer ' comment As String data(32) As Byte End Type Public Declare Function rsa_generate Lib "ALCrypto" (ptrKey As RSAKey, ByVal bits As Long, ByVal pfn As Long, ByVal pfnparam As Long) As Long Public Declare Function rsa_public_key_blob Lib "ALCrypto" (ptrKey As RSAKey, ByVal blob As String, blobLen As Long) As Long Public Declare Function rsa_private_key_blob Lib "ALCrypto" (ptrKey As RSAKey, ByVal blob As String, blobLen As Long) As Long Public Declare Function rsa_createkey Lib "ALCrypto" (ByVal pub_blob As String, ByVal pub_len As Long, ByVal priv_blob As String, ByVal priv_len As Long, ptrKey As RSAKey) As Long Public Declare Function rsa_encrypt Lib "ALCrypto" (ByVal CryptType As Long, ByVal data As String, dLen As Long, ptrKey As RSAKey) As Long Public Declare Function rsa_decrypt Lib "ALCrypto" (ByVal CryptType As Long, ByVal data As String, dLen As Long, ptrKey As RSAKey) As Long Public Declare Function rsa_sign Lib "ALCrypto" (ByRef ptrKey As RSAKey, ByVal data As String, ByVal dLen As Long, ByVal sig As String, ByRef sLen As Long) As Long Public Declare Function rsa_verifysig Lib "ALCrypto" (ByRef ptrKey As RSAKey, ByVal sig As String, ByVal sLen As Long, ByVal data As String, ByVal dLen As Long) As Long Public Declare Function fnRSA Lib "ALCrypto" (ptrKey As RSAKey, ByVal bits As Long, ByVal pfn As Long, ByVal pfnparam As Long) As Long 'Public Declare Function fnRSA Lib "rsa" (ByVal bits As Long, ptrKey As RSAKey, ByVal pfn As Long, ByVal pfnparam As Long) Private Const MAXPHASE& = 5 Type PhaseType exponential As Byte startpoint As Byte total As Byte param As Byte current As Byte n As Byte ' if exponential */ mult As Byte ' if linear */ End Type Type ProgressType nphases As Long phases(0 To MAXPHASE - 1) As PhaseType total As Byte divisor As Byte range As Byte hwndProgbar As Long End Type Public Sub ProgressUpdate(ByVal param As Long, ByVal action As Long, ByVal phase As Long, ByVal iprogress As Long) Debug.Print "Progress Update received " & param & ", action: " & action & ", iprogress: " & iprogress End Sub Sub Main() Debug.Print "here!" End Sub Private Function FnPtrLong(ptr As Long) As Long FnPtrLong = ptr End Function '' ' Converts a string into a hex string. ' Private Function Str2Hex(str As String) As String Dim strHex$ Dim arrBytes() As Byte arrBytes = StrConv(str, vbFromUnicode) Dim I& Dim charHex As String For I = LBound(arrBytes) To UBound(arrBytes) charHex = Hex(arrBytes(I)) If Len(charHex) = 1 Then ' pad leading zero charHex = "0" & charHex End If strHex = strHex & charHex Next Str2Hex = strHex End Function --- NEW FILE: Project1.vbp --- Type=Exe Form=Form1.frm Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\System32\stdole2.tlb#OLE Automation Module=Module1; Module1.bas Module=modBase64; ..\..\activelock2\src\modBase64.bas IconForm="Form1" Startup="Form1" HelpFile="" ExeName32="Project1.exe" Command32="" Name="Project1" HelpContextID="0" CompatibleMode="0" MajorVer=1 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="Karora Technologies Inc." CompilationType=0 OptimizationType=0 FavorPentiumPro(tm)=0 CodeViewDebugInfo=0 NoAliasing=0 BoundsCheck=0 OverflowCheck=0 FlPointCheck=0 FDIVCheck=0 UnroundedFP=0 StartMode=0 Unattended=0 Retained=0 ThreadPerObject=0 MaxNumberOfThreads=1 [MS Transaction Server] AutoRefresh=1 |