AutoIt
AutoIt
RSA Sign Binary Data and Verify (Recover the Original Data)
See more RSA Examples
Demonstrates how to RSA sign binary data and then verify/recover the original data.Note: This example uses methods introduced in Chilkat v9.5.0.77.
Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; Load an RSA private key for signing.
$oPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivKey.LoadEncryptedPemFile("qa_data/pem/rsa_passwd.pem","passwd")
If ($bSuccess = False) Then
ConsoleWrite($oPrivKey.LastErrorText & @CRLF)
Exit
EndIf
$oRsa = ObjCreate("Chilkat.Rsa")
$oRsa.UsePrivateKey($oPrivKey)
; We have some binary data (in hex) to sign
Local $sOriginalData = "0102030405060708090A"
$oBd = ObjCreate("Chilkat.BinData")
$oBd.AppendEncoded($sOriginalData,"hex")
; If successful, the contents of bd are replaced with the RSA signature.
$bSuccess = $oRsa.SignRawBd($oBd)
If ($bSuccess = False) Then
ConsoleWrite($oRsa.LastErrorText & @CRLF)
Exit
EndIf
; Show the RSA signature in base64
ConsoleWrite($oBd.GetEncoded("base64") & @CRLF)
; ------------------------------------------
; Get the public key from the private key
$oPubKey = ObjCreate("Chilkat.PublicKey")
$oPrivKey.ToPublicKey($oPubKey)
; Verify the signature and extract the original data.
$oRsa2 = ObjCreate("Chilkat.Rsa")
$oRsa2.UsePublicKey($oPubKey)
Local $bVerified = $oRsa2.VerifyRawBd($oBd)
ConsoleWrite("signature verified: " & $bVerified & @CRLF)
; Show the original data:
ConsoleWrite("original data: " & $oBd.GetEncoded("hex") & @CRLF)