Activecrypt Online Help Prev Next
About ActiveCrypt
About
ActiveCrypt overview
How to ...
How to make pair of keys
Create new public key from private
How to decrypt string
How to encrypt string
How to save keys
Free keys
Programmer reference
Hash
Hash overview
Methods
HashFile
HashVariant
Properties
Error
Crypt
Encryption overview
Methods
DecryptFile
DecryptVariant
EncryptFile
EncryptVariant
FreeKey
LoadKeyFromString
LoadKey
Properties
AddCRLF
Error
KeySize
Base64
Base64 overview
Methods
DecodeFile
DecodeVariant
EncodeFile
EncodeVariant
Properties
AddCRLF
Error
Sign
Sign overview
Methods
FreeKey
LoadKey
LoadKeyFromString
MakeVariantSignature
MakeFileSignature
VerifyFileSignature
VerifyVariantSignature
Properties
AddCRLF
Error
RSACrypt (old, use Crypt)
Methods
FreeKey
GenerateCouple
GeneratePublicKey
GetVersion
LoadKeyFromString
LoadKey
PublicEncrypt
PrivateDecrypt
SaveKeyToString
SaveKey
Properties
About
Async
Error
Events
OnDecryptionFinished
OnEncryptionFinished
OnError
OnKeyGenerationFinished
Disclaimer

Async

property boolean Async

It is a special property of ActiveCrypt component that lets you execute long running operations in the background thread. The functions that benefit from Asynchronous mode are : GenerateCouple, PublicEncrypt, PrivateDecrypt. By default that property is set to FALSE. This means that your program will wait for a request to be completed by ActiveCrypt component. This is quite an easy mode and it is enough for the successful functioning of the program. Bun in this case the program will be blocked during data procession. If you need to process large amounts of data simultaneously without blocking you should choose the asynchronous mode.

To turn the the asynchronous mode you need to set the property to TRUE. Since that, the functionsGenerateCouple, PublicEncrypt, PrivateDecrypt return immediately invalid keys or empty strings. And after the work of those functions is completed successfully they fire the following events: OnKeyGenerationFinished, OnEncryptionFinished, OnDecryptionFinished respectively or OnError in the case of an error.

In order to handle data in events correctly and define what this data refers to, a special cookie ID should be added to GenerateCouple, PublicEncrypt, PrivateDecrypt. You can omit them in the synchronous mode, but in the asynchronous mode they are quite useful. The following example demonstrates how to take advantage of asynchronous encryption and use cookies.

Example:

        Dim WithEvents ActiveCryptObject As ActiveCryptLib.RSACrypt
        'do not forget to specify WithEvents keyword, otherwise, it will not get any events at all
        Dim PrivateKey As Variant
        Dim PublicKey As Variant

        Private Sub ActiveCryptObject_OnDecryptionFinished(ByVal Cookie As Long, ByVal DecryptedText As String)
                'do with DecryptedText what you want, or just put it in a ListBox ;)
                List1.AddItem Str(Cookie)+" "+DecryptedText
        End Sub

        Private Sub ActiveCryptObject_OnEncryptionFinished(ByVal Cookie As Long, ByVal CryptedText As String)
                ActiveCryptObject.PrivateDecrypt PrivateKey, CryptedText, Cookie 
        End Sub

        Private Sub ActiveCryptObject_OnError(ByVal Cookie As Long, ByVal ErrorNumber As Long, ByVal ErrorMsg As String)
                List1.AddItem "Error: "+ErrorMsg
        EndSub

        Private Sub Command1_Click()
                ActiveCryptObject.Async =True
                ' let's say here we open some looooong file and read 20000 
                ' records into ClearData string and then encrypt it in the asyncronous mode
                For  i = 0 To20000
                        'read into ClearData
                        ActiveCryptObject.PublicEncrypt, PublicKey, ClearData, i 
                Next i
                'the program goes further ....
        End Sub

This HTML Help has been published using the chm2web software.