Java 类org.bouncycastle.crypto.signers.PSSSigner 实例源码

项目:xitk    文件:SignerUtil.java   
public static PSSSigner createPSSRSASigner(AlgorithmIdentifier sigAlgId,
        AsymmetricBlockCipher cipher) throws XiSecurityException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
        throw new XiSecurityException("signature algorithm " + sigAlgId.getAlgorithm()
            + " is not allowed");
    }

    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgFromSigAlg(sigAlgId);
    } catch (NoSuchAlgorithmException ex) {
        throw new XiSecurityException(ex.getMessage(), ex);
    }

    RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());

    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier.getInstance(
            param.getMaskGenAlgorithm().getParameters());

    Digest dig = getDigest(digAlgId);
    Digest mfgDig = getDigest(mfgDigAlgId);

    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();
    AsymmetricBlockCipher tmpCipher = (cipher == null) ? new RSABlindedEngine() : cipher;

    return new PSSSigner(tmpCipher, dig, mfgDig, saltSize, getTrailer(trailerField));
}
项目:xitk    文件:SignerUtil.java   
private static byte getTrailer(int trailerField) {
    if (trailerField == 1) {
        return org.bouncycastle.crypto.signers.PSSSigner.TRAILER_IMPLICIT;
    }

    throw new IllegalArgumentException("unknown trailer field");
}
项目:gwt-crypto    文件:PSSBlindTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, new FixedRandom(slt)));

    blindSigner.update(msg, 0, msg.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //signature verification
    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    //verify signature with PSSSigner
    signer.init(false, pub);
    signer.update(msg, 0, msg.length);

    if (!signer.verifySignature(s))
    {
        fail("test " + id + " failed PSSSigner verification");
    }
}
项目:gwt-crypto    文件:PSSTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    PSSSigner           eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    eng.init(true, new ParametersWithRandom(prv, new FixedRandom(slt)));

    eng.update(msg, 0, msg.length);

    byte[]  s = eng.generateSignature();

    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    eng.init(false, pub);

    eng.update(msg, 0, msg.length);

    if (!eng.verifySignature(s))
    {
        fail("test " + id + " failed verification");
    }
}
项目:easy-vote    文件:CriptoUtils.java   
/**
 * Verifies that a text matches the given signature
 * @param key   Public key that pairs up with the used private key to generate the given signature
 * @param msg   The message to check upon
 * @param sig   The signature that has to match the given msg text
 * @return  True if the given text is valid upon the given signature, false otherwise
 */
public static boolean verify(CipherParameters key, byte[] msg, byte[] sig) {
    /*
     * Typical methods and arguments
     */
    PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), saltLength);
    signer.init(false, key);

    signer.update(msg,0,msg.length);

    return signer.verifySignature(sig);
}
项目:irma_future_id    文件:PSSTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    PSSSigner           eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    eng.init(true, new ParametersWithRandom(prv, new FixedRandom(slt)));

    eng.update(msg, 0, msg.length);

    byte[]  s = eng.generateSignature();

    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    eng.init(false, pub);

    eng.update(msg, 0, msg.length);

    if (!eng.verifySignature(s))
    {
        fail("test " + id + " failed verification");
    }
}
项目:bc-java    文件:PSSTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    PSSSigner           eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    eng.init(true, new ParametersWithRandom(prv, new FixedRandom(slt)));

    eng.update(msg, 0, msg.length);

    byte[]  s = eng.generateSignature();

    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    eng.init(false, pub);

    eng.update(msg, 0, msg.length);

    if (!eng.verifySignature(s))
    {
        fail("test " + id + " failed verification");
    }
}
项目:xitk    文件:SignerUtil.java   
public static PSSSigner createPSSRSASigner(AlgorithmIdentifier sigAlgId)
        throws XiSecurityException {
    return createPSSRSASigner(sigAlgId, null);
}
项目:xitk    文件:P11RSAPSSContentSigner.java   
PSSSignerOutputStream(PSSSigner pssSigner) {
    this.pssSigner = pssSigner;
}
项目:gwt-crypto    文件:PSSBlindTest.java   
private boolean isProcessingOkay(
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              data,
    SecureRandom        random)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner pssEng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    random.nextBytes(data);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, random));

    blindSigner.update(data, 0, data.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //verify signature with PSSSigner
    pssEng.init(false, pub);
    pssEng.update(data, 0, data.length);

    return pssEng.verifySignature(s);
}
项目:irma_future_id    文件:PSSBlindTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, new FixedRandom(slt)));

    blindSigner.update(msg, 0, msg.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //signature verification
    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    //verify signature with PSSSigner
    signer.init(false, pub);
    signer.update(msg, 0, msg.length);

    if (!signer.verifySignature(s))
    {
        fail("test " + id + " failed PSSSigner verification");
    }
}
项目:irma_future_id    文件:PSSBlindTest.java   
private boolean isProcessingOkay(
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              data,
    SecureRandom        random)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner pssEng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    random.nextBytes(data);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, random));

    blindSigner.update(data, 0, data.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //verify signature with PSSSigner
    pssEng.init(false, pub);
    pssEng.update(data, 0, data.length);

    return pssEng.verifySignature(s);
}
项目:bc-java    文件:PSSBlindTest.java   
private void testSig(
    int                 id,
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              slt,
    byte[]              msg,
    byte[]              sig)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner signer = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, new FixedRandom(slt)));

    blindSigner.update(msg, 0, msg.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //signature verification
    if (!areEqual(s, sig))
    {
        fail("test " + id + " failed generation");
    }

    //verify signature with PSSSigner
    signer.init(false, pub);
    signer.update(msg, 0, msg.length);

    if (!signer.verifySignature(s))
    {
        fail("test " + id + " failed PSSSigner verification");
    }
}
项目:bc-java    文件:PSSBlindTest.java   
private boolean isProcessingOkay(
    RSAKeyParameters    pub,
    RSAKeyParameters    prv,
    byte[]              data,
    SecureRandom        random)
    throws Exception
{
    RSABlindingFactorGenerator blindFactorGen = new RSABlindingFactorGenerator();
    RSABlindingEngine blindingEngine = new RSABlindingEngine();
    PSSSigner blindSigner = new PSSSigner(blindingEngine, new SHA1Digest(), 20);
    PSSSigner pssEng = new PSSSigner(new RSAEngine(), new SHA1Digest(), 20);

    random.nextBytes(data);

    blindFactorGen.init(pub);

    BigInteger blindFactor = blindFactorGen.generateBlindingFactor();
    RSABlindingParameters params = new RSABlindingParameters(pub, blindFactor);

    // generate a blind signature
    blindSigner.init(true, new ParametersWithRandom(params, random));

    blindSigner.update(data, 0, data.length);

    byte[] blindedData = blindSigner.generateSignature();

    RSAEngine signerEngine = new RSAEngine();

    signerEngine.init(true, prv);

    byte[] blindedSig = signerEngine.processBlock(blindedData, 0, blindedData.length);

    // unblind the signature
    blindingEngine.init(false, params);

    byte[] s = blindingEngine.processBlock(blindedSig, 0, blindedSig.length);

    //verify signature with PSSSigner
    pssEng.init(false, pub);
    pssEng.update(data, 0, data.length);

    return pssEng.verifySignature(s);
}