本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKey.addCertification方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKey.addCertification方法的具体用法?Java PGPPublicKey.addCertification怎么用?Java PGPPublicKey.addCertification使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKey
的用法示例。
在下文中一共展示了PGPPublicKey.addCertification方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signPublicKey
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Signs a public key
*
* @param publicKeyRing a public key ring containing the single public key to sign
* @param id the id we are certifying against the public key
* @param secretKey the signing key
* @param secretKeyPassword the signing key password
*
* @return a public key ring with the signed public key
*/
public static PGPPublicKeyRing signPublicKey( PGPPublicKeyRing publicKeyRing, String id, PGPSecretKey secretKey,
String secretKeyPassword ) throws PGPException
{
try
{
PGPPublicKey oldKey = publicKeyRing.getPublicKey();
PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
.build( secretKeyPassword.toCharArray() ) );
PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder( secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1 ) );
signatureGenerator.init( PGPSignature.DEFAULT_CERTIFICATION, pgpPrivKey );
PGPSignature signature = signatureGenerator.generateCertification( id, oldKey );
PGPPublicKey newKey = PGPPublicKey.addCertification( oldKey, signature );
PGPPublicKeyRing newPublicKeyRing = PGPPublicKeyRing.removePublicKey( publicKeyRing, oldKey );
return PGPPublicKeyRing.insertPublicKey( newPublicKeyRing, newKey );
}
catch ( Exception e )
{
//throw custom exception
throw new PGPException( "Error signing public key", e );
}
}
示例2: copySignatures
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
private static PGPPublicKey copySignatures( PGPPublicKey targetKey, PGPPublicKey sourceKey )
{
Map<Long, PGPSignature> targetSigs = getSignatures( targetKey );
Map<Long, PGPSignature> sourceSigs = getSignatures( sourceKey );
for ( Map.Entry<Long, PGPSignature> e : sourceSigs.entrySet() )
{
if ( !targetSigs.containsKey( e.getKey() ) )
{
targetKey = PGPPublicKey.addCertification( targetKey, e.getValue() );
}
}
return targetKey;
}
示例3: embeddedJpegTest
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
private void embeddedJpegTest()
throws Exception
{
PGPPublicKeyRing pgpPub = new PGPPublicKeyRing(testPubKey, new BcKeyFingerprintCalculator());
PGPSecretKeyRing pgpSec = new PGPSecretKeyRing(testPrivKey, new BcKeyFingerprintCalculator());
PGPPublicKey pubKey = pgpPub.getPublicKey();
PGPUserAttributeSubpacketVectorGenerator vGen = new PGPUserAttributeSubpacketVectorGenerator();
vGen.setImageAttribute(ImageAttribute.JPEG, jpegImage);
PGPUserAttributeSubpacketVector uVec = vGen.generate();
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(PublicKeyAlgorithmTags.RSA_GENERAL, HashAlgorithmTags.SHA1));
sGen.init(PGPSignature.POSITIVE_CERTIFICATION, pgpSec.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass)));
PGPSignature sig = sGen.generateCertification(uVec, pubKey);
PGPPublicKey nKey = PGPPublicKey.addCertification(pubKey, uVec, sig);
Iterator it = nKey.getUserAttributes();
int count = 0;
while (it.hasNext())
{
PGPUserAttributeSubpacketVector attributes = (PGPUserAttributeSubpacketVector)it.next();
Iterator sigs = nKey.getSignaturesForUserAttribute(attributes);
int sigCount = 0;
while (sigs.hasNext())
{
PGPSignature s = (PGPSignature)sigs.next();
s.init(new BcPGPContentVerifierBuilderProvider(), pubKey);
if (!s.verifyCertification(attributes, pubKey))
{
fail("added signature failed verification");
}
sigCount++;
}
if (sigCount != 1)
{
fail("Failed added user attributes signature check");
}
count++;
}
if (count != 1)
{
fail("didn't find added user attributes");
}
nKey = PGPPublicKey.removeCertification(nKey, uVec);
count = 0;
for (it = nKey.getUserAttributes(); it.hasNext();)
{
count++;
}
if (count != 0)
{
fail("found attributes where none expected");
}
}