I was trying to create JWT ("JOT") token for make my api call authentic. When ever I try creating token with RSA512 signature, I get back an error saying
java.lang.IllegalArgumentException: RSA signatures must be computed using an RSA PrivateKey. The specified key of type javax.crypto.spec.SecretKeySpec is not an RSA PrivateKey.
I am using below code:
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RS512;
long nowMillis = System.currentTimeMillis();
Date now = new Date(nowMillis);
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(SECRET_KEY);
Key signingKey = new SecretKeySpec(apiKeySecretBytes,
signatureAlgorithm.getJcaName());
JwtBuilder builder = Jwts.builder().claim("uuid",
id).setIssuedAt(now).setExpiration(new Date(600000))
.signWith(signatureAlgorithm, signingKey);
Note : My "SECRET_KEY" is a string which is a private key generated randomly online . my questionis how can I get a Key object from a string encoded with RSA key size as 4096. 4096 since I am using RSA512 encryption, it is recommended to use 4096 key for RSA512
verify signature - your-256-bit-secret- jpsSECRET_KEY. Can you post the key? - jps-----BEGIN RSA PRIVATE KEY----- MIICXgIBAAKBgQDHikastc8+I81zCg/qWW8dMr8mqvXQ3qbPAmu0RjxoZVI47tvs...5vg087ZngKfFGR5rozDiTsK5DceTV97K a3Y+Nzl+XWTxDBWk4YPh2ZlKv402hZEfWBYxUDn5ZkH/bw== -----END RSA PRIVATE KEY-----On this site you can create keys for testing. - jps