I'm actually using an apex implementation of jwt for the rsa256 cryptography type using this class from github : https://github.com/salesforceidentity/jwt.
I have been able to generate a signature and the resulting token, but when I'm trying to use the below apex code to validate the signature :
public Boolean verifySignature(String algorithmName, Blob input, Blob signature){
string publicKey = 'MIIDCTCCAfGgAwIBAgIUWKbDV0W7B/EJ8GNEZy5uSB9zZgkwDQYJKoZIhvcNAQEL' +
'some lines omitted for security reason here' +
'1pOkGqtTdGkIo8HGeuBp1NWwm/c2cRcn+FzM3MWYAbdvfku09L2plHvrcjd1w8bT' +
'Q5XsXcDAPUEevQ9xVg==';
Blob key = EncodingUtil.base64Decode(publicKey);
return Crypto.verify(algorithmName, input, signature, key);
}
I am having this error :
System.SecurityException: Invalid Crypto Key
My public key and private key works well in jwt.io when trying to generate a token.
In the salesforce documentation it is written that :
The value of publicKey must be decoded using the EncodingUtilbase64Decode method, and be in X.509 standard.
This is what I have done , and my public key is a valid x.509 public key.
I generated it with openssl using the following command :
openssl req -nodes -x509 -sha256 -newkey rsa:2048 -keyout rsa_private.pem -out rsa_public_cert.pem -days 365 -subj /CN=TEST_JWT_JAVA_XXXXX
What can be the cause?