@Test public void testPartialBufferVerification() throws Exception { Signer signer = factory.getInstance(true, privateKey); byte[] source = new byte[text.length * 2]; System.arraycopy(text, 0, source, text.length - 10, text.length); byte[] signature = signer.generate(source, text.length - 10, text.length); byte[] sign = new byte[signature.length * 2]; System.arraycopy(signature, 0, sign, signature.length - 5, signature.length); Signer verifier = factory.getInstance(true, publicKey); assertTrue( verifier.verify(sign, signature.length - 5, signature.length, source, text.length - 10, text.length)); }
@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);  }