Fang Wang
2014-03-12 07:15:36 UTC
Hi,
Does anyone know how to verify signature created by OpenSSL (with RSASSA_PSS algorithm) in Java? The default Java Crypto lib does not seem to support PSS padding. I tried Bouncy Castle (with "SHA256withRSA/PSS" algorithm) w/o a success. With OpenSSL, what I did was as following:
- Initialize: EVP_PKEY_sign_init
- Set padding: EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING)
- Create digest/hash
- Sign the hash: EVP_PKEY_sign
In Bouncy Castle (BC), I did the following:
byte[] signature = Base64.decodeBase64(sigText);
Base64 base64 = new Base64();
byte [] decoded = base64.decode(publicKeyPEM);
X509EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
PublicKey key = kf.generatePublic(spec);
Signature ss = Signature.getInstance("SHA256withRSA/PSS", "BC");
AlgorithmParameters pss1 = ss.getParameters();
PSSParameterSpec spec1 = new PSSParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), 32, 1);
ss.setParameter(spec1);
ss.initVerify(key);
ss.update(rawData.getBytes());
boolean result = ss.verify(signature);
I tried different parameters for PSSParameterSpec without a success. Did I do anything wrong with the algorithms or parameters?
Thanks!
Does anyone know how to verify signature created by OpenSSL (with RSASSA_PSS algorithm) in Java? The default Java Crypto lib does not seem to support PSS padding. I tried Bouncy Castle (with "SHA256withRSA/PSS" algorithm) w/o a success. With OpenSSL, what I did was as following:
- Initialize: EVP_PKEY_sign_init
- Set padding: EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING)
- Create digest/hash
- Sign the hash: EVP_PKEY_sign
In Bouncy Castle (BC), I did the following:
byte[] signature = Base64.decodeBase64(sigText);
Base64 base64 = new Base64();
byte [] decoded = base64.decode(publicKeyPEM);
X509EncodedKeySpec spec = new X509EncodedKeySpec(decoded);
KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
PublicKey key = kf.generatePublic(spec);
Signature ss = Signature.getInstance("SHA256withRSA/PSS", "BC");
AlgorithmParameters pss1 = ss.getParameters();
PSSParameterSpec spec1 = new PSSParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), 32, 1);
ss.setParameter(spec1);
ss.initVerify(key);
ss.update(rawData.getBytes());
boolean result = ss.verify(signature);
I tried different parameters for PSSParameterSpec without a success. Did I do anything wrong with the algorithms or parameters?
Thanks!