I am trying to generate the payload for a rest API and part of the payload is a digital signature using our private key.
The private key is generated from an external source using openssl, with AES-256 encryption as below:
openssl genrsa -aes256 -passout pass:{password} -out {location} 2048
and then converted to PKCS#8 format also using openssl.
I am using the CrypterObject AsymmetricSign function to generate the signature using the PKCS#8 private key but I get an Invalid privKey error.
Does PB2019 support encrypted private keys for AsymmetricSign? If so, are there additional steps that need to be done before I call this function?
Thanks,
Eric
Below is the sample code:
String ls_private_key_pkcs8
Blob lblb_private_key, lblb_hash, lblb_sign
CrypterObject lnv_CrypterObject
CoderObject lnv_CoderObject
lnv_CrypterObject = Create CrypterObject
lnv_CoderObject = Create CoderObject
ls_private_key_pkcs8 = 'MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQI77MkcuVWINQCAggA'
ls_private_key_pkcs8 += 'MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBD3UscJJMjByZaOQnhrEXF1BIIE'
ls_private_key_pkcs8 += '0LygIgD3de0dMf9zvPnaNEMG2JNZow42DQjN7EOo+ni4blH+AgYB1jWzH+1BWkQn'
…
…
…
lblb_private_key = lnv_CoderObject.Base64Decode(ls_private_key_pkcs8)
lblb_hash = lnv_CrypterObject.SHA(SHA256!, Blob('Key=Value', EncodingUTF8!))
lblb_sign = lnv_CrypterObject.AsymmetricSign(RSA!, lblb_hash, lblb_private_key)
openssl pkcs8 -topk8 -in {encrypted private key file} -out {pkcs8 encrypted private key file}
converts the private key to PKCS#8 format using AES with 256 bit key and hmacWithSHA256.
How should I go about to decrypt this? The SymmetricDecrypt function only has the algorithm (AES256) as parameter.
Also another noob question, do I decrypt the key BEFORE or AFTER i base64 decode the key?
Thanks!