Package org.bouncycastle.openpgp

Examples of org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator


      owner.getPublicKey().getAlgorithm(),
      HashAlgorithm.DEFAULT.toInteger(),
      "BC");
    signatureGenerator.initSign(PGPSignature.BINARY_DOCUMENT, owner.getPrivateKey());

    final PGPSignatureSubpacketGenerator signatureMetaData = new PGPSignatureSubpacketGenerator();
    signatureMetaData.setSignerUserID(false, owner.getUserID());
    signatureGenerator.setHashedSubpackets(signatureMetaData.generate());
    return signatureGenerator;
  }
View Full Code Here


        PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(sigKeyPassword.toCharArray(), "BC");
        if (sigPrivateKey == null) {
            throw new IllegalArgumentException("Signature private key is null, cannot proceed");
        }

        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
        spGen.setSignerUserID(false, sigKeyUserid);

        int algorithm = sigSecretKey.getPublicKey().getAlgorithm();
        PGPSignatureGenerator sigGen = new PGPSignatureGenerator(algorithm, HashAlgorithmTags.SHA1, "BC");
        sigGen.initSign(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
        sigGen.setHashedSubpackets(spGen.generate());
        sigGen.generateOnePassVersion(false).encode(out);
        return sigGen;
    }
View Full Code Here

        BCPGOutputStream            bOut = new BCPGOutputStream(out);

        sGen.generateOnePassVersion(false).encode(bOut);

        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();

        boolean isHumanReadable = true;

        spGen.setNotationData(true, isHumanReadable, notationName, notationValue);

        PGPSignatureSubpacketVector packetVector = spGen.generate();
        sGen.setHashedSubpackets(packetVector);

        bOut.flush();

        return PGPPublicKey.addCertification(keyToBeSigned, sGen.generate()).getEncoded();
View Full Code Here

        }
       
        PGPSecretKey                    pgpSecKey = readSecretKey(keyIn);
        PGPPrivateKey                   pgpPrivKey = pgpSecKey.extractPrivateKey(pass, "BC");       
        PGPSignatureGenerator           sGen = new PGPSignatureGenerator(pgpSecKey.getPublicKey().getAlgorithm(), digest, "BC");
        PGPSignatureSubpacketGenerator  spGen = new PGPSignatureSubpacketGenerator();
       
        sGen.initSign(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
       
        Iterator    it = pgpSecKey.getPublicKey().getUserIDs();
        if (it.hasNext())
        {
            spGen.setSignerUserID(false, (String)it.next());
            sGen.setHashedSubpackets(spGen.generate());
        }
       
        FileInputStream        fIn = new FileInputStream(fileName);
        ArmoredOutputStream    aOut = new ArmoredOutputStream(out);
       
View Full Code Here

        sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
       
        Iterator    it = pgpSec.getPublicKey().getUserIDs();
        if (it.hasNext())
        {
            PGPSignatureSubpacketGenerator  spGen = new PGPSignatureSubpacketGenerator();
           
            spGen.setSignerUserID(false, (String)it.next());
            sGen.setHashedSubpackets(spGen.generate());
        }
       
        PGPCompressedDataGenerator  cGen = new PGPCompressedDataGenerator(
                                                                PGPCompressedData.ZLIB);
       
View Full Code Here

       
        sGen = new PGPSignatureGenerator(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1, "BC");
       
        sGen.initSign(PGPSignature.SUBKEY_BINDING, pgpPrivDSAKey);

        PGPSignatureSubpacketGenerator    unhashedGen = new PGPSignatureSubpacketGenerator();
        PGPSignatureSubpacketGenerator    hashedGen = new PGPSignatureSubpacketGenerator();
       
        hashedGen.setSignatureExpirationTime(false, TEST_EXPIRATION_TIME);
        hashedGen.setSignerUserID(true, TEST_USER_ID);
        hashedGen.setPreferredCompressionAlgorithms(false, PREFERRED_COMPRESSION_ALGORITHMS);
        hashedGen.setPreferredHashAlgorithms(false, PREFERRED_HASH_ALGORITHMS);
        hashedGen.setPreferredSymmetricAlgorithms(false, PREFERRED_SYMMETRIC_ALGORITHMS);

        sGen.setHashedSubpackets(hashedGen.generate());
        sGen.setUnhashedSubpackets(unhashedGen.generate());
       
        sig = sGen.generateCertification(secretDSAKey.getPublicKey(), secretKey.getPublicKey());

        byte[] sigBytes = sig.getEncoded();
       
        PGPObjectFactory f = new PGPObjectFactory(sigBytes);
       
        sig = ((PGPSignatureList) f.nextObject()).get(0);
       
        sig.initVerify(secretDSAKey.getPublicKey(), "BC");
       
        if (!sig.verifyCertification(secretDSAKey.getPublicKey(), secretKey.getPublicKey()))
        {
            fail("subkey binding verification failed.");
        }
       
        PGPSignatureSubpacketVector hashedPcks = sig.getHashedSubPackets();
        PGPSignatureSubpacketVector unhashedPcks = sig.getUnhashedSubPackets();
       
        if (hashedPcks.size() != 6)
        {
            fail("wrong number of hashed packets found.");
        }

        if (unhashedPcks.size() != 1)
        {
            fail("wrong number of unhashed packets found.");
        }

        if (!hashedPcks.getSignerUserID().equals(TEST_USER_ID))
        {
            fail("test userid not matching");
        }
       
        if (hashedPcks.getSignatureExpirationTime() != TEST_EXPIRATION_TIME)
        {
            fail("test signature expiration time not matching");
        }
       
        if (unhashedPcks.getIssuerKeyID() != secretDSAKey.getKeyID())
        {
            fail("wrong issuer key ID found in certification");
        }
       
        int[] prefAlgs = hashedPcks.getPreferredCompressionAlgorithms();
        preferredAlgorithmCheck("compression", PREFERRED_COMPRESSION_ALGORITHMS, prefAlgs);

        prefAlgs = hashedPcks.getPreferredHashAlgorithms();
        preferredAlgorithmCheck("hash", PREFERRED_HASH_ALGORITHMS, prefAlgs);
       
        prefAlgs = hashedPcks.getPreferredSymmetricAlgorithms();
        preferredAlgorithmCheck("symmetric", PREFERRED_SYMMETRIC_ALGORITHMS, prefAlgs);
       
        int[] criticalHashed = hashedPcks.getCriticalTags();
       
        if (criticalHashed.length != 1)
        {
            fail("wrong number of critical packets found.");
        }
       
        if (criticalHashed[0] != SignatureSubpacketTags.SIGNER_USER_ID)
        {
            fail("wrong critical packet found in tag list.");
        }
       
        //
        // no packets passed
        //
        sGen = new PGPSignatureGenerator(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1, "BC");
       
        sGen.initSign(PGPSignature.SUBKEY_BINDING, pgpPrivDSAKey);

        sGen.setHashedSubpackets(null);
        sGen.setUnhashedSubpackets(null);

        sig = sGen.generateCertification(TEST_USER_ID, secretKey.getPublicKey());
       
        sig.initVerify(secretDSAKey.getPublicKey(), "BC");
       
        if (!sig.verifyCertification(TEST_USER_ID, secretKey.getPublicKey()))
        {
            fail("subkey binding verification failed.");
        }
       
        hashedPcks = sig.getHashedSubPackets();
       
        if (hashedPcks.size() != 1)
        {
            fail("found wrong number of hashed packets");
        }
       
        unhashedPcks = sig.getUnhashedSubPackets();
       
        if (unhashedPcks.size() != 1)
        {
            fail("found wrong number of unhashed packets");
        }
       
        try
        {
            sig.verifyCertification(secretKey.getPublicKey());
           
            fail("failed to detect non-key signature.");
        }
        catch (IllegalStateException e)
        {
            // expected
        }
       
        //
        // override hash packets
        //
        sGen = new PGPSignatureGenerator(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1, "BC");
       
        sGen.initSign(PGPSignature.SUBKEY_BINDING, pgpPrivDSAKey);

        hashedGen = new PGPSignatureSubpacketGenerator();
       
        hashedGen.setSignatureCreationTime(false, new Date(0L));
       
        sGen.setHashedSubpackets(hashedGen.generate());
       
        sGen.setUnhashedSubpackets(null);

        sig = sGen.generateCertification(TEST_USER_ID, secretKey.getPublicKey());
       
View Full Code Here

        PGPSignatureGenerator signGen = new PGPSignatureGenerator(secretKey.getPublicKey().getAlgorithm(),
                        PGPUtil.SHA1, "BC");
        signGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
        Iterator it = secretKey.getPublicKey().getUserIDs();
        if (it.hasNext()) {
            PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
            spGen.setSignerUserID(false, (String) it.next());
            signGen.setHashedSubpackets(spGen.generate());
        }
        v4signer = signGen;
        onePassSignature = v4signer.generateOnePassVersion(false);
    }
View Full Code Here

        ByteArrayInputStream    testIn = new ByteArrayInputStream(data.getBytes());
        PGPSignatureGenerator   sGen = new PGPSignatureGenerator(PublicKeyAlgorithmTags.DSA, HashAlgorithmTags.SHA1, "BC");
   
        sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);

        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
       
        Iterator        it = sKey.getSecretKey().getPublicKey().getUserIDs();
        String          primaryUserID = (String)it.next();
       
        spGen.setSignerUserID(true, primaryUserID);
       
        sGen.setHashedSubpackets(spGen.generate());
       
        PGPCompressedDataGenerator cGen = new PGPCompressedDataGenerator(
                                                                PGPCompressedData.ZIP);

        BCPGOutputStream bcOut = new BCPGOutputStream(
View Full Code Here

    }

    private void setHashedSubpackets(final PGPSignatureGenerator signatureGenerator) {
        final Iterator<String> it = key.getPublicKey().getUserIDs();
        if (it.hasNext()) {
            final PGPSignatureSubpacketGenerator generator = new PGPSignatureSubpacketGenerator();
            generator.setSignerUserID(false, it.next());
            signatureGenerator.setHashedSubpackets(generator.generate());
        }
    }
View Full Code Here

        PGPPrivateKey sigPrivateKey = sigSecretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(sigKeyPassword.toCharArray()));
        if (sigPrivateKey == null) {
            throw new IllegalArgumentException("Signature private key is null, cannot proceed");
        }

        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
        spGen.setSignerUserID(false, sigKeyUserid);

        int algorithm = sigSecretKey.getPublicKey().getAlgorithm();
        PGPSignatureGenerator sigGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(algorithm, HashAlgorithmTags.SHA1).setProvider("BC"));
        sigGen.init(PGPSignature.BINARY_DOCUMENT, sigPrivateKey);
        sigGen.setHashedSubpackets(spGen.generate());
        sigGen.generateOnePassVersion(false).encode(out);
        return sigGen;
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.