PowerBuilder
PowerBuilder
RSA Signature using Private Key from .snk File
See more RSA Examples
A .snk file (Strong Name Key file) is a file format used in the .NET ecosystem to store an RSA public/private key pair. This key pair is typically used for strong-naming assemblies, which is a process of signing .NET assemblies to ensure their integrity and to uniquely identify them.This example loads a private key from a .snk file and creates an RSA signature.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rsa
string ls_XmlStr
oleobject loo_PrivKey
string ls_SigBase64
li_Success = 0
loo_Rsa = create oleobject
li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa")
if li_rc < 0 then
destroy loo_Rsa
MessageBox("Error","Connecting to COM object failed")
return
end if
// Load the .snk and return the private key as XML.
ls_XmlStr = loo_Rsa.SnkToXml("./test.snk")
if loo_Rsa.LastMethodSuccess = 0 then
Write-Debug loo_Rsa.LastErrorText
destroy loo_Rsa
return
end if
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
li_Success = loo_PrivKey.LoadXml(ls_XmlStr)
if li_Success = 0 then
Write-Debug loo_PrivKey.LastErrorText
destroy loo_Rsa
destroy loo_PrivKey
return
end if
li_Success = loo_Rsa.UsePrivateKey(loo_PrivKey)
if li_Success = 0 then
Write-Debug loo_Rsa.LastErrorText
destroy loo_Rsa
destroy loo_PrivKey
return
end if
// Sign the SHA-256 hash of the utf-8 byte representation of the contents of sb
// Return the signature in base64 format.
loo_Rsa.EncodingMode = "base64"
loo_Rsa.Charset = "utf-8"
ls_SigBase64 = loo_Rsa.SignStringENC("This is the text to be hashed and signed.","sha256")
if loo_Rsa.LastMethodSuccess = 0 then
Write-Debug loo_Rsa.LastErrorText
destroy loo_Rsa
destroy loo_PrivKey
return
end if
Write-Debug "RSA signature as base64: " + ls_SigBase64
destroy loo_Rsa
destroy loo_PrivKey