AutoIt
AutoIt
RSA Hash Binary Data and Sign (and Verify)
See more RSA Examples
Demonstrates how to sign the hash of binary data. Also demonstrates how to verify the RSA signature.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"
$oBdData = ObjCreate("Chilkat.BinData")
$oBdData.AppendEncoded($sOriginalData,"hex")
; Hash (SHA-256) and sign the hash:
$oBdSignature = ObjCreate("Chilkat.BinData")
$bSuccess = $oRsa.SignBd($oBdData,"sha256",$oBdSignature)
If ($bSuccess = False) Then
ConsoleWrite($oRsa.LastErrorText & @CRLF)
Exit
EndIf
; Show the RSA signature in base64
ConsoleWrite($oBdSignature.GetEncoded("base64") & @CRLF)
; ------------------------------------------
; Get the public key from the private key
$oPubKey = ObjCreate("Chilkat.PublicKey")
$oPrivKey.ToPublicKey($oPubKey)
; Verify the signature..
$oRsa2 = ObjCreate("Chilkat.Rsa")
$oRsa2.UsePublicKey($oPubKey)
Local $bVerified = $oRsa2.VerifyBd($oBdData,"sha256",$oBdSignature)
ConsoleWrite("signature verified: " & $bVerified & @CRLF)