You need to sign in to do that
Don't have an account?

Crypto.sign giving exception in winter 17 for developers
Hi all,
I am using following code to genrate sign, It is working fine in summer 16 salesforce release but my org it autmatically upgraded to winter 17 and this code starts giving follwoing exception:-
"EXCEPTION: System.SecurityException: Invalid Crypto Key
STACKTRACE: Class.System.Crypto.sign: line 35, column 1
AnonymousBlock: line 7, column 1
AnonymousBlock: line 7, column 1
LINE: 35 COLUMN: 1"
can any one help me on this???
I am using following code to genrate sign, It is working fine in summer 16 salesforce release but my org it autmatically upgraded to winter 17 and this code starts giving follwoing exception:-
"EXCEPTION: System.SecurityException: Invalid Crypto Key
STACKTRACE: Class.System.Crypto.sign: line 35, column 1
AnonymousBlock: line 7, column 1
AnonymousBlock: line 7, column 1
LINE: 35 COLUMN: 1"
can any one help me on this???
string modifiedPrivateKey = 'MIIEpAIBAAKCAQEA1l9J+lUhM3RIADiLy2ajqUjltBqSVMthUlNnu8GsN4z85aniBIDebY+RkFhKDDW9hu8xM/Q4NEI7klmCVWI5BnobWfUjRbhd9oW94qBP7B1Ka6BsSn3RbfvGZZLcDNXd6806acpgMn79fjYPUQPI1kSfrd1GeMDQDGtNFsnCTd9zq2Vye4RQJrlDzC7g70i3jEHCh853ifD4MaQwo+SWf/eF7bLqA+81qUB2llRyA7SH9YF1I/ZmgH57MVTXb62HRMr/JxERDOerHLt7CK9hdbmM3vpRZz8MJnIMrNJKXXbxS69F8aLK7q+8i8xkl1IRwWVD9uJJaWpz7NEBs9EenwIDAQABAoIBACRDLjJoYBtiGiPfbNZVYG3sZN7Yd9RcKvRQI4YBNu6WrNj0qcT1P6rs1ETEipISLSM8JuiQ8Uj1wzn4ZjGnUdokoafP7c2HaG2hJgPF9n8MXWBjXK4lJl4ibucTtqF9M/MFXlIy557jGGJXJrQfncORDCnO+nLGuuq+4+Vs769YQ+bfj69pzfo4kUKaZRj6tgDcAo9Owbe6b7t1gGIM1fo+1fnyZrgYUxwor6periyvjefJaw8N78ASXbu9zHvVrbqaZmwXRJqCRRm8yY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QiOiJodHRwczovL2FwaS5ib3guY29tL29hdXRoMi90b2tlbiIsImp0aSI6InRKVFRwUklmRFhFUlNkNjFBS0hIam9wUm41ZEVSMjBMIiwiZXhwIjoxNDc2MDg4ODA4fQ'; string jwtHeader = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InAwbXE4aHZqIn0'; String algorithmName = 'RSA-SHA256'; Blob input = Blob.valueOf(jwtHeader + '.' + jwtClaims); Blob privateKeyBlob = EncodingUtil.base64Decode(modifiedPrivateKey); Blob signed = Crypto.sign(algorithmName, input, privateKeyBlob);Thanks Anurag
Hi Anurag,
Did you got any solution for this. I am also facing same issue. If you get any solution for this let me know.
Thanks,
Srini
The modifiedPrivateKey need to be in PKCS#8 format. The documentation says "The value of privateKey must be decoded using the EncodingUtilbase64Decode method, and should be in RSA's PKCS #8 (1.2) Private-Key Information Syntax Standard form. The value cannot exceed 4 KB.".
The easy way to get the pkcs8 format is to use Open SSL command to convert the private key to PKCS#8 format. Thanks.
Did you get any solution for this. I am also facing this issue. if you found an solution please share with us.
Thanks in advance.