|
Code samples available on this page:
Symmetric Key String Encryption/Decryption
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim CipherData As String
Dim ClearData As String
Dim Password As String
'--- define the password ---
Password = "My Password"
'--- Encrypt ---
CipherData = DynCrypto.SymEncrypt("MyPassword", "MyTestString")
'--- Decrypt ---
ClearData = DynCrypto.SymDecrypt("MyPassword", CipherData)
|
Asymmetric Key String Encryption/Decryption
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim CipherData As String
Dim ClearData As String
Dim PublicKey As String
Dim PrivateKey As String
'--- define the password ---
PrivateKey = "MyPrivateKey"
'--- create the public key
PublicKey = DynCrypto.AsymPublicKey(PrivateKey)
'--- Encrypt ---
CipherData = DynCrypto.AsymEncrypt(PublicKey, "MyTestString")
'--- Decrypt ---
ClearData = DynCrypto.AsymDecrypt(PrivateKey, CipherData)
|
Generate a Hash value from a String
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim HashValue As String
'-- Generate the Hash Value ---
HashValue = DynCrypto.Hash("MyTestString")
|
Asymmetric Key File Encryption/Decryption
The code below assume that C:\TEMP\MYTESTFILE.TXT exists and that C:\TEMP\OUT is valid directory.
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim PrivateKey As String
Dim PublicKey As String
Dim ClearFile As String
Dim CipherFile As String
Dim OutDir As String
Dim ClearFileOut As String
Dim Result As Int32
Dim HashCheck As Boolean
'--- define the password ---
PrivateKey = "MyPrivateKey"
'--- create the public key
PublicKey = DynCrypto.AsymPublicKey(PrivateKey)
'--- Specify the file to encrypt
ClearFile = "C:\temp\MyTestFile.txt"
'--- Specify the output directory
OutDir = "C:\temp\out"
'--- We encrypt the file.
'--- The crypted file full path is returned in "CipherFile"
Result = DynCrypto.AsymEncryptFile(PublicKey, ClearFile, OutDir, CipherFile, True)
If Result <> 0 Then
'--- Error. Result contain the Win32 error code.
End If
'--- We decrypt the crypted file.
'--- The clear file full path is returned in "ClearFileOut"
Result = DynCrypto.AsymDecryptFile(PrivateKey, CipherFile, OutDir, ClearFileOut, HashCheck)
If (Not HashCheck) Or Result <> 0 Then
'--- Error. Invalid private key, cipher data was corrupted
Else
'--- Success. File was decrypted. Private key is valid
End If
|
Symmetric Key File Encryption/Decryption
The code below assume that C:\TEMP\MYTESTFILE.TXT exists and that C:\TEMP\OUT is valid directory.
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim Password As String
Dim ClearFile As String
Dim CipherFile As String
Dim OutDir As String
Dim ClearFileOut As String
Dim Result As Int32
Dim HashCheck As Boolean
'--- define the password ---
Password = "MyPassword"
'--- Specify the file to encrypt
ClearFile = "C:\temp\MyTestFile.txt"
'--- Specify the output directory
OutDir = "C:\temp\out"
'--- We encrypt the file.
'--- The crypted file full path is returned in "CipherFile"
Result = DynCrypto.SymEncryptFile(Password, ClearFile, OutDir, CipherFile, True)
If Result <> 0 Then
'--- Error. Result contain the Win32 error code.
End If
'--- We decrypt the crypted file.
'--- The clear file full path is returned in "ClearFileOut"
Result = DynCrypto.SymDecryptFile(Password, CipherFile, OutDir, ClearFileOut, HashCheck)
If (Not HashCheck) Or Result <> 0 Then
'--- Error. Invalid private key, cipher data was corrupted
Else
'--- Success. File was decrypted. Private key is valid
End If
|
Generate a Hash value from a File
The sample code below creates a Hash value from file C:\TEMP\CLEAR.TXT. The result is
stored in a String variable:
'--- Create a DynCrypto instance ---
Dim DynCrypto As New dyncrypto
'--- Declare variables ---
Dim HashValue As String
'-- Generate the Hash Value ---
HashValue = dyncrypto.HashFile("C:\temp\MyTestFile.txt")
|
|