@Test public void sign() throws Exception { AbstractPrivateKey rsaPrivateKey = pssSpec.getPrivateKey(); assertArrayEquals(rsaPrivateKey.sign(pssSpec.M, HashType.SHA1, RSASSAPSSTestVectors.salt), pssSpec.S); }
@Override public byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); final PSSSigner signer; if (salt == null) { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize())); } else { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), salt); } signer.init(true, 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 { signer.update(buffer, 0, howManyBytesRead); } } } try { return signer.generateSignature(); } catch (CryptoException e) { throw new IOException(String.format("Cannot sign data: %s", e.toString())); } } }
RSAOAEPPrivateKey extends AbstractPrivateKey { @Override public byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); final PSSSigner signer; if (salt == null) { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize())); } else { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), salt); } signer.init(true, 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 { signer.update(buffer, 0, howManyBytesRead); } } } try { return signer.generateSignature(); } catch (CryptoException e) { throw new IOException(String.format("Cannot sign data: %s", e.toString())); } } } }
RSAOAEPPrivateKey extends AbstractPrivateKey { @Override public byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); final PSSSigner signer; if (salt == null) { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize())); } else { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), salt); } signer.init(true, 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 { signer.update(buffer, 0, howManyBytesRead); } } } try { return signer.generateSignature(); } catch (CryptoException e) { throw new IOException(String.format("Cannot sign data: %s", e.toString())); } } } RSAOAEPPrivateKey();   RSAOAEPPrivateKey(byte[] e, byte[] p, byte[] q, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); }
RSAOAEPPrivateKey extends AbstractPrivateKey { @Override public byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); final PSSSigner signer; if (salt == null) { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize())); } else { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), salt); } signer.init(true, 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 { signer.update(buffer, 0, howManyBytesRead); } } } try { return signer.generateSignature(); } catch (CryptoException e) { throw new IOException(String.format("Cannot sign data: %s", e.toString())); } } } RSAOAEPPrivateKey();   RSAOAEPPrivateKey(byte[] e, byte[] p, byte[] q, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); @Override String toString(); @Override void generate(int bitStrength, HashType mgf1HashType); void generate(int bitStrength, byte[] e, int certainty, HashType oaepHashType, HashType mgf1HashType); @Override boolean isInitialized(); @Override int getBitStrength(); @Override AbstractPublicKey getPublicKey(); @Override boolean canDecrypt(); @Override byte[] decrypt(byte[] ciphertext); @Override byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt); @NonNull @Override Map<String, Object> toHash(); @Override void updateFromHash(Map<String, Object> hash); @Override byte[] pack(); }
RSAOAEPPrivateKey extends AbstractPrivateKey { @Override public byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt) throws IllegalStateException, IOException { if (state == null) { throw new IllegalStateException(); } else { final Digest primaryDigest = hashType.makeDigest(); final PSSSigner signer; if (salt == null) { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), getMaxSaltLength(getBitStrength(), primaryDigest.getDigestSize())); } else { signer = new PSSSigner( RSAEngineFactory.make(), primaryDigest, state.mgf1HashType.makeDigest(), salt); } signer.init(true, 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 { signer.update(buffer, 0, howManyBytesRead); } } } try { return signer.generateSignature(); } catch (CryptoException e) { throw new IOException(String.format("Cannot sign data: %s", e.toString())); } } } RSAOAEPPrivateKey();   RSAOAEPPrivateKey(byte[] e, byte[] p, byte[] q, HashType oaepHashType, HashType mgf1HashType, SecureRandom rng); @Override String toString(); @Override void generate(int bitStrength, HashType mgf1HashType); void generate(int bitStrength, byte[] e, int certainty, HashType oaepHashType, HashType mgf1HashType); @Override boolean isInitialized(); @Override int getBitStrength(); @Override AbstractPublicKey getPublicKey(); @Override boolean canDecrypt(); @Override byte[] decrypt(byte[] ciphertext); @Override byte[] sign(InputStream input, HashType hashType, @Nullable byte[] salt); @NonNull @Override Map<String, Object> toHash(); @Override void updateFromHash(Map<String, Object> hash); @Override byte[] pack(); static final HashType DEFAULT_OAEP_HASH; static final HashType DEFAULT_MGF1_HASH; }