Normally both PSS
and PKCS1v15
can be used for RSA signatures padding.
And for java the code is also simple, but it just can't tell the padding strategy used.
My code:
Signature signature = Signature.getInstance("SHA1WithRSA");
signature.initSign(privateKey);
signature.update(plainBytes);
byte[] signBytes = signature.sign();
May I explicitly define PSS
with MGF1
as the padding strategy using SunJCE as provider?
thanks @xuanzhui
Here is how I successfully verified my (hex encoded) signature:
Note despite the documentation suggesting otherwise (
getSaltLength()
- "returns the salt length in bits") salt length seems to be in bytes!Also I think "SHA512withRSA/PSS" is only supported from Android 23+
PSS
is not present in the supported algorithms list of SunJCE. HoweverSHA256withRSA/PSS
is implemented in android.I suggest to use BouncyCastle
UPDATED
The default
maskGenAlgorithm
in PKCS#1 v2.1 is MGF1.I assume BouncyCastle is using it. You can define your own PSS parameters. For example (see PSSParameterSpec)
Inspired by the answer, just to add a snippet that shows how to set all the params manually, and of course
BouncyCastle
has to be used: