Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRsa
LOCAL cXmlStr
LOCAL oPrivKey
LOCAL cSigBase64
nSuccess := 0
oRsa := CreateObject("Chilkat.Rsa")
// Load the .snk and return the private key as XML.
cXmlStr := oRsa:SnkToXml("./test.snk")
IF (oRsa:LastMethodSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
RETURN
ENDIF
oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oPrivKey:LoadXml(cXmlStr)
IF (nSuccess == 0)
? oPrivKey:LastErrorText
oRsa:destroy()
oPrivKey:destroy()
RETURN
ENDIF
nSuccess := oRsa:UsePrivateKey(oPrivKey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
oPrivKey:destroy()
RETURN
ENDIF
// Sign the SHA-256 hash of the utf-8 byte representation of the contents of sb
// Return the signature in base64 format.
oRsa:EncodingMode := "base64"
oRsa:Charset := "utf-8"
cSigBase64 := oRsa:SignStringENC("This is the text to be hashed and signed.", "sha256")
IF (oRsa:LastMethodSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
oPrivKey:destroy()
RETURN
ENDIF
? "RSA signature as base64: " + cSigBase64
oRsa:destroy()
oPrivKey:destroy()