AutoIt
AutoIt
Verify the RSA Signature of a SHA256 Hash
See more RSA Examples
Demonstrates how to verify an RSA signature of a SHA256 hash.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; Let's say you have a file containing the 32-bytes of a SHA256 hash,
; and a file that is an RSA signature of those 32 bytes.
; Here's how you verify using the RSA public key found in a PEM.
$oPubKey = ObjCreate("Chilkat.PublicKey")
$bSuccess = $oPubKey.LoadFromFile("rsaPubKey.pem")
If ($bSuccess = False) Then
ConsoleWrite($oPubKey.LastErrorText & @CRLF)
Exit
EndIf
$oRsa = ObjCreate("Chilkat.Rsa")
; Get the public key.
$bSuccess = $oRsa.UsePublicKey($oPubKey)
If ($bSuccess = False) Then
ConsoleWrite($oRsa.LastErrorText & @CRLF)
Exit
EndIf
; Get the 32-byte SHA256 hash.
$oBdHash = ObjCreate("Chilkat.BinData")
$bSuccess = $oBdHash.LoadFile("myHash.sha256")
If ($bSuccess = False) Then
ConsoleWrite("Failed to load SHA256 hash." & @CRLF)
Exit
EndIf
; Get the RSA signature to be validated.
$oBdSig = ObjCreate("Chilkat.BinData")
$bSuccess = $oBdSig.LoadFile("mySig.sig")
If ($bSuccess = False) Then
ConsoleWrite("Failed to load RSA signature." & @CRLF)
Exit
EndIf
; Verify the signature against the SHA256 hash.
Local $sEnc = "base64"
$oRsa.EncodingMode = $sEnc
$bSuccess = $oRsa.VerifyHashENC($oBdHash.GetEncoded($sEnc),"sha256",$oBdSig.GetEncoded($sEnc))
If ($bSuccess = False) Then
ConsoleWrite($oRsa.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Signature validated." & @CRLF)