You need to sign in to do that
Don't have an account?
Francesco Sciuto
Exception thrown when trying to sign with RSA-SHA1 using Crypto.Sign
I am struggling with signing an input with a key generated by using OpenSSL. My code is as follows:
string algorithmName = 'RSA-SHA1' //also tried with 'RSA'
String base64String = 'KBfW9103GQKknExCqOStSmczmNwDNF81yrF04AVvoVI=';
Blob privateKey = EncodingUtil.base64Decode(base64String);
Blob input = Blob.valueOf('12345qwerty');
Crypto.sign(algorithmName, input, privateKey);
The base64String is obtained with the command: openssl rand -base64 32
Everytime I run the code I get the following exception in the log:
"common.apex.runtime.impl.ExecutionException: Invalid Crypto Key"|0x4809a271
Does anybody have an idea what am I doing wrong? Thanks
string algorithmName = 'RSA-SHA1' //also tried with 'RSA'
String base64String = 'KBfW9103GQKknExCqOStSmczmNwDNF81yrF04AVvoVI=';
Blob privateKey = EncodingUtil.base64Decode(base64String);
Blob input = Blob.valueOf('12345qwerty');
Crypto.sign(algorithmName, input, privateKey);
The base64String is obtained with the command: openssl rand -base64 32
Everytime I run the code I get the following exception in the log:
"common.apex.runtime.impl.ExecutionException: Invalid Crypto Key"|0x4809a271
Does anybody have an idea what am I doing wrong? Thanks
String algorithmName = 'hmacSHA1';
String base64String = 'KBfW9103GQKknExCqOStSmczmNwDNF81yrF04AVvoVI=';
Blob privateKey = EncodingUtil.base64Decode(base64String);
Blob input = Blob.valueOf('12345qwerty');
Crypto.generateMac(algorithmName, input, privateKey);
All Answers
String algorithmName = 'hmacSHA1';
String base64String = 'KBfW9103GQKknExCqOStSmczmNwDNF81yrF04AVvoVI=';
Blob privateKey = EncodingUtil.base64Decode(base64String);
Blob input = Blob.valueOf('12345qwerty');
Crypto.generateMac(algorithmName, input, privateKey);
1. Remove `-----START PRIVATE KEY-----`
2. Remove `-----END PRIVATE KEY-----`,
3. Remove all line changes `\n`