@Test public void testStreamSignatureVerification() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(text); Signer signer = factory.getInstance(true, privateKey); InputStream input = signer.getInputStream(bais); byte[] buf = new byte[text.length]; assertThat(readAll(input, buf), equalTo(text.length)); assertThat(buf, equalTo(text)); byte[] signature = signer.generate(); Signer verifier = factory.getInstance(false, publicKey); OutputStream output = verifier.getOutputStream(); output.write(text); assertTrue(verifier.verify(signature)); }
@Override public Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId) { if (!algId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { throw new IllegalArgumentException("Incompatible algorithm for this signer: " + algId.getAlgorithm().getId()); } ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else { RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier .getInstance(pssParams.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }
BcRsaSsaPssSignerFactory extends AbstractBcPssSignerFactory { @Override public Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId) { if (!algId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { throw new IllegalArgumentException("Incompatible algorithm for this signer: " + algId.getAlgorithm().getId()); } ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else { RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier .getInstance(pssParams.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); } }
BcRsaSsaPssSignerFactory extends AbstractBcPssSignerFactory { @Override public Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId) { if (!algId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { throw new IllegalArgumentException("Incompatible algorithm for this signer: " + algId.getAlgorithm().getId()); } ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else { RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier .getInstance(pssParams.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }  }
BcRsaSsaPssSignerFactory extends AbstractBcPssSignerFactory { @Override public Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId) { if (!algId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { throw new IllegalArgumentException("Incompatible algorithm for this signer: " + algId.getAlgorithm().getId()); } ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else { RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier .getInstance(pssParams.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }  @Override Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId); }
BcRsaSsaPssSignerFactory extends AbstractBcPssSignerFactory { @Override public Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId) { if (!algId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) { throw new IllegalArgumentException("Incompatible algorithm for this signer: " + algId.getAlgorithm().getId()); } ASN1Encodable algParams = algId.getParameters(); if (DERNull.INSTANCE.equals(algParams)) { return getInstance(forSigning, parameters); } else { RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(algId.getParameters()); if (parameters instanceof AsymmetricKeyParameters) { return getInstance(forSigning, new PssSignerParameters((AsymmetricKeyParameters) parameters, pssParams.getHashAlgorithm().getAlgorithm().getId(), AlgorithmIdentifier .getInstance(pssParams.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId(), pssParams.getSaltLength().intValue(), pssParams.getTrailerField().intValue())); } } throw new UnsupportedOperationException(PSS_PARAMS_ERROR + parameters.getClass().getName()); }  @Override Signer getInstance(boolean forSigning, CipherParameters parameters, AlgorithmIdentifier algId);  }