@Test public void checkSignature() throws Exception { AbstractPublicKey rsaPublicKey = pssSpec.getPublicKey(); AbstractPrivateKey rsaPrivateKey = pssSpec.getPrivateKey(); assertArrayEquals( rsaPrivateKey.sign(pssSpec.M, HashType.SHA1, RSASSAPSSTestVectors.salt), pssSpec.S); assertTrue(rsaPublicKey.checkSignature( pssSpec.M, rsaPrivateKey.sign(pssSpec.M, HashType.SHA1, RSASSAPSSTestVectors.salt), HashType.SHA1, RSASSAPSSTestVectors.salt.length)); }
@NonNull @Override public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); if (saltLength == MAX_SALT_LENGTH) { saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize()); } if (saltLength < 0) { throw new RuntimeException(String.format("Incorrect salt length %s", saltLength)); } final Signer signatureChecker = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength); signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); boolean done = false; while (!done) { int availableBytes = input.available(); if (availableBytes <= 0) { done = true; } else { byte[] buffer = new byte[availableBytes]; int howManyBytesRead = input.read(buffer); if (howManyBytesRead <= 0) { done = true; } else { signatureChecker.update(buffer, 0, howManyBytesRead); } } } return signatureChecker.verifySignature(signature); } }
RSAOAEPPublicKey extends AbstractPublicKey { @NonNull @Override public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); if (saltLength == MAX_SALT_LENGTH) { saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize()); } if (saltLength < 0) { throw new RuntimeException(String.format("Incorrect salt length %s", saltLength)); } final Signer signatureChecker = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength); signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); boolean done = false; while (!done) { int availableBytes = input.available(); if (availableBytes <= 0) { done = true; } else { byte[] buffer = new byte[availableBytes]; int howManyBytesRead = input.read(buffer); if (howManyBytesRead <= 0) { done = true; } else { signatureChecker.update(buffer, 0, howManyBytesRead); } } } return signatureChecker.verifySignature(signature); } } }
RSAOAEPPublicKey extends AbstractPublicKey { @NonNull @Override public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); if (saltLength == MAX_SALT_LENGTH) { saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize()); } if (saltLength < 0) { throw new RuntimeException(String.format("Incorrect salt length %s", saltLength)); } final Signer signatureChecker = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength); signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); boolean done = false; while (!done) { int availableBytes = input.available(); if (availableBytes <= 0) { done = true; } else { byte[] buffer = new byte[availableBytes]; int howManyBytesRead = input.read(buffer); if (howManyBytesRead <= 0) { done = true; } else { signatureChecker.update(buffer, 0, howManyBytesRead); } } } return signatureChecker.verifySignature(signature); } } RSAOAEPPublicKey();   RSAOAEPPublicKey(byte[] n, byte[] e, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); }
RSAOAEPPublicKey extends AbstractPublicKey { @NonNull @Override public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); if (saltLength == MAX_SALT_LENGTH) { saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize()); } if (saltLength < 0) { throw new RuntimeException(String.format("Incorrect salt length %s", saltLength)); } final Signer signatureChecker = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength); signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); boolean done = false; while (!done) { int availableBytes = input.available(); if (availableBytes <= 0) { done = true; } else { byte[] buffer = new byte[availableBytes]; int howManyBytesRead = input.read(buffer); if (howManyBytesRead <= 0) { done = true; } else { signatureChecker.update(buffer, 0, howManyBytesRead); } } } return signatureChecker.verifySignature(signature); } } RSAOAEPPublicKey();   RSAOAEPPublicKey(byte[] n, byte[] e, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); @Override String toString(); @Override boolean canEncrypt(); @Override int getBitStrength(); @Override boolean isInitialized(); @NonNull @Override byte[] encrypt(byte[] plaintext); @NonNull @Override boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength); @NonNull @Override String algorithmTag(); @NonNull @Override Map<String, Object> toHash(); @Override void updateFromHash(Map<String, Object> hash); }
RSAOAEPPublicKey extends AbstractPublicKey { @NonNull @Override public boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); if (saltLength == MAX_SALT_LENGTH) { saltLength = getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize()); } if (saltLength < 0) { throw new RuntimeException(String.format("Incorrect salt length %s", saltLength)); } final Signer signatureChecker = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), saltLength); signatureChecker.init(false, new ParametersWithRandom(state.keyParameters, state.rng)); boolean done = false; while (!done) { int availableBytes = input.available(); if (availableBytes <= 0) { done = true; } else { byte[] buffer = new byte[availableBytes]; int howManyBytesRead = input.read(buffer); if (howManyBytesRead <= 0) { done = true; } else { signatureChecker.update(buffer, 0, howManyBytesRead); } } } return signatureChecker.verifySignature(signature); } } RSAOAEPPublicKey();   RSAOAEPPublicKey(byte[] n, byte[] e, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); @Override String toString(); @Override boolean canEncrypt(); @Override int getBitStrength(); @Override boolean isInitialized(); @NonNull @Override byte[] encrypt(byte[] plaintext); @NonNull @Override boolean checkSignature(InputStream input, byte[] signature, HashType hashType, int saltLength); @NonNull @Override String algorithmTag(); @NonNull @Override Map<String, Object> toHash(); @Override void updateFromHash(Map<String, Object> hash); static final HashType DEFAULT_OAEP_HASH; static final HashType DEFAULT_MGF1_HASH; }