RSA Data Encryption/Decryption

Most smartcards (but not all) also contain a certificate to decrypt public key encrypted data. This functions are mapped directly to the Aloaha EncryptedStringBA and DecryptedString Properties.

Please note that RSA encryption is only usable for relatively short values. The length of the RSA encryptable string depends on the keylength. To be on the safe side it should not be longer than approx. 160 bytes!


EncryptedStringBA

EncryptedStringBA encrypts any String with the given public key. For this function no smartcard is being required!

EncryptedStringBA(ByVal publickeyBA As Variant, ByVal inputstring As String, ByVal RSA_Padding As RSAPadding) As Variant.

RSA_Padding defines the padding type used. Supported types are:

NONE = 0
PKCS = 1
OAEP = 2
SSL = 3

Encrypting is a FREEWARE function of Aloaha!


DecryptedString

DecryptedString returns the decrypted Value of InputBA. The operation is carried out on the smartcard!

DecryptedString(ByVal CertificateThumbPrint As String, ByVal InputBA As Variant, ByVal ctype As CertificateType, ByVal RSA_Padding As RSAPadding) As String


Sample Code

Dim csp As Object
Dim parser As Object


Private Sub Command1_Click() 

   Const PKCS = 1
   Dim LngReader As Long
   Dim CertificateBA() As Byte
   Dim CA_BA() As Byte
   Dim ctype As Long
   Dim searchfilter As Long
   Dim fingerprint As String
   Dim publicKeyBA() As Byte
   Dim ClearTextString As String
   Dim EncryptedValueBA() As Byte
   Dim DecryptedString As String
 
   LngReader = 0               'for 1st connected card reader
   searchfilter = 2               'searchfilter "Fingerprint" 
   ctype = 2                         'Encryption Certificate on Card 

   ClearTextString = "Aloaha" 

   'Read encryption cert from first card reader connected
   If csp.get_certificate_by_reader(LngReader, CertificateBA, CA_BA, ctype) = True Then 

     'Load the cert to mem to parse it for fingerprint
     Call parser.LoadCertificateToMemory(CertificateBA, False)
     fingerprint = parser.fingerprint(True) 

     'connect Aloaha to the found certificate
     If csp.FindCertificate(fingerprint, searchfilter, ctype, fingerprint, CertificateBA) > -1 Then 
        
        'get public key
        publicKeyBA = csp.publicKeyBA(fingerprint, ctype) 

        'RSA encrypt the string "Aloaha"
        EncryptedValueBA = csp.EncryptedStringBA(publicKeyBA, ClearTextString, PKCS) 

        'Decrypt the encrypted value on the card
        DecryptedString = csp.DecryptedString(fingerprint, EncryptedValueBA, ctype, PKCS) 

        MsgBox DecryptedString
     End If
   End If
End Sub

Private Sub Form_Load()
     Set csp = CreateObject("AloahaCertInstaller.provider")
     Set parser = CreateObject("AloahaCertInstaller.CertificateParser")
End Sub


Private Sub Form_Terminate()
     Set csp = Nothing
     Set parser = Nothing
End Sub




Aloaha Software / Knowledge Base / Smart Card API / Aloaha CSP API / Data Encryption

create PDF Software

Data Encryption

Any questions?
Aloaha Software - Smart Card API / Aloaha CSP API / Data Encryption
ProductsKnowledge BaseShopSupportPress
Deutsche VersionEnglish version