RsaSsaPssSignJce implements PublicKeySign { @Override public byte[] sign(final byte[] data) throws GeneralSecurityException { int modBits = publicKey.getModulus().bitLength(); byte[] em = emsaPssEncode(data, modBits - 1); return rsasp1(em); } RsaSsaPssSignJce(
      final RSAPrivateCrtKey priv, HashType sigHash, HashType mgf1Hash, int saltLength); @Override byte[] sign(final byte[] data);  }
@Test public void testBasicAgainstVerifier() throws Exception { if (TestUtil.isTsan()) { return; } int keySize = 2048; KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(keySize); KeyPair keyPair = keyGen.generateKeyPair(); RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic(); RSAPrivateCrtKey priv = (RSAPrivateCrtKey) keyPair.getPrivate(); byte[] message = "Hello".getBytes(UTF_8); RsaSsaPssSignJce signer = new RsaSsaPssSignJce(priv, HashType.SHA256, HashType.SHA256, 32); for (int i = 0; i < 1024; i++) { byte[] signature = signer.sign(message); RsaSsaPssVerifyJce verifier = new RsaSsaPssVerifyJce(pub, HashType.SHA256, HashType.SHA256, 32); try { verifier.verify(signature, message); } catch (GeneralSecurityException e) { throw new AssertionError("Valid signature, shouldn't throw exception", e); } } }
@Test public void testZeroSaltLength() throws Exception { if (TestUtil.isTsan()) { return; } int keySize = 2048; KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(keySize); KeyPair keyPair = keyGen.generateKeyPair(); RSAPublicKey pub = (RSAPublicKey) keyPair.getPublic(); RSAPrivateCrtKey priv = (RSAPrivateCrtKey) keyPair.getPrivate(); byte[] message = "Hello".getBytes(UTF_8); RsaSsaPssSignJce signer = new RsaSsaPssSignJce(priv, HashType.SHA256, HashType.SHA256, 0); byte[] signature = signer.sign(message); RsaSsaPssVerifyJce verifier = new RsaSsaPssVerifyJce(pub, HashType.SHA256, HashType.SHA256, 0); try { verifier.verify(signature, message); } catch (GeneralSecurityException e) { throw new AssertionError("Valid signature, shouldn't throw exception", e); } }