Example usage for org.bouncycastle.openpgp PGPSignatureSubpacketGenerator setNotationData

List of usage examples for org.bouncycastle.openpgp PGPSignatureSubpacketGenerator setNotationData

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPSignatureSubpacketGenerator setNotationData.

Prototype

public void setNotationData(boolean isCritical, boolean isHumanReadable, String notationName,
            String notationValue) 

Source Link

Usage

From source file:org.sufficientlysecure.keychain.pgp.UncachedKeyRing.java

License:Open Source License

@VisibleForTesting
public static UncachedKeyRing forTestingOnlyAddDummyLocalSignature(UncachedKeyRing uncachedKeyRing,
        String passphrase) throws Exception {
    PGPSecretKeyRing sKR = (PGPSecretKeyRing) uncachedKeyRing.mRing;

    PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder()
            .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray());
    PGPPrivateKey masterPrivateKey = sKR.getSecretKey().extractPrivateKey(keyDecryptor);
    PGPPublicKey masterPublicKey = uncachedKeyRing.mRing.getPublicKey();

    // add packet with "pin" notation data
    PGPContentSignerBuilder signerBuilder = new JcaPGPContentSignerBuilder(
            masterPrivateKey.getPublicKeyPacket().getAlgorithm(),
            PgpSecurityConstants.SECRET_KEY_BINDING_SIGNATURE_HASH_ALGO)
                    .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
    PGPSignatureGenerator sGen = new PGPSignatureGenerator(signerBuilder);
    { // set subpackets
        PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator();
        hashedPacketsGen.setExportable(false, false);
        hashedPacketsGen.setNotationData(false, true, "dummynotationdata", "some data");
        sGen.setHashedSubpackets(hashedPacketsGen.generate());
    }/* w w  w . j  a va  2  s  . com*/
    sGen.init(PGPSignature.DIRECT_KEY, masterPrivateKey);
    PGPSignature emptySig = sGen.generateCertification(masterPublicKey);

    masterPublicKey = PGPPublicKey.addCertification(masterPublicKey, emptySig);
    sKR = PGPSecretKeyRing.insertSecretKey(sKR,
            PGPSecretKey.replacePublicKey(sKR.getSecretKey(), masterPublicKey));

    return new UncachedKeyRing(sKR);
}