(PowerShell) RSA Sign using Base64 Private Key
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.
Add-Type -Path "C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll"
# This requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
$privKey = New-Object Chilkat.PrivateKey
$sbPem = New-Object Chilkat.StringBuilder
$sbPem.AppendLine("-----BEGIN RSA PRIVATE KEY-----",$true)
$sbPem.AppendLine("MIIC .... j5A==",$true)
$sbPem.AppendLine("-----END RSA PRIVATE KEY-----",$true)
$success = $privKey.LoadPem($sbPem.GetAsString())
if ($success -ne $true) {
$($privKey.LastErrorText)
exit
}
$rsa = New-Object Chilkat.Rsa
$success = $rsa.ImportPrivateKeyObj($privKey)
if ($success -ne $true) {
$($rsa.LastErrorText)
exit
}
$rsa.EncodingMode = "base64"
$strSigned = $rsa.OpenSslSignStringENC("12345678")
$($strSigned)
$strOriginal = $rsa.OpenSslVerifyStringENC($strSigned)
$($strOriginal)
|