 |
About ActiveCrypt |
 |
How to ... |
 |
Programmer reference |
 |
Hash |
 |
Methods |
 |
Properties |
 |
Crypt |
 |
Methods |
 |
Properties |
 |
Base64 |
 |
Methods |
 |
Properties |
 |
Sign |
 |
Methods |
 |
Properties |
 |
RSACrypt (old, use Crypt) |
 |
Methods |
 |
Properties |
 |
Events |
|
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
|
|