本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKey.getKeyID方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKey.getKeyID方法的具体用法?Java PGPPublicKey.getKeyID怎么用?Java PGPPublicKey.getKeyID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPPublicKey
的用法示例。
在下文中一共展示了PGPPublicKey.getKeyID方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public PGPContentVerifier build(final PGPPublicKey publicKey)
throws PGPException
{
final Signer signer = BcImplProvider.createSigner(keyAlgorithm, hashAlgorithm);
signer.init(false, keyConverter.getPublicKey(publicKey));
return new PGPContentVerifier()
{
public int getHashAlgorithm()
{
return hashAlgorithm;
}
public int getKeyAlgorithm()
{
return keyAlgorithm;
}
public long getKeyID()
{
return publicKey.getKeyID();
}
public boolean verify(byte[] expected)
{
return signer.verifySignature(expected);
}
public OutputStream getOutputStream()
{
return new SignerOutputStream(signer);
}
};
}
示例2: test6
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public void test6()
throws Exception
{
PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(pub6, new BcKeyFingerprintCalculator());
Iterator rIt = pubRings.getKeyRings();
while (rIt.hasNext())
{
PGPPublicKeyRing pgpPub = (PGPPublicKeyRing)rIt.next();
Iterator it = pgpPub.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey k = (PGPPublicKey)it.next();
if (k.getKeyID() == 0x5ce086b5b5a18ff4L)
{
int count = 0;
Iterator sIt = k.getSignaturesOfType(PGPSignature.SUBKEY_REVOCATION);
while (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
count++;
}
if (count != 1)
{
fail("wrong number of revocations in test6.");
}
}
}
}
byte[] encRing = pubRings.getEncoded();
}
示例3: readPublicKey
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
/**
* Reads the public key from the specified key file.
*
* @param in - Stream pointing to key store.
* @param fingerPrintCalculator - An alogrithm to be used for fingerprint calculation.
* This sample uses BcKeyFingerprintCalculator algorithm.
* @return Returns a public key read from the specified key file.
* @throws IOException
* @throws PGPException
* @throws CryptDecryptException
*/
private PGPPublicKey readPublicKey() throws IOException, PGPException, CryptDecryptException {
if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.readPublicKey", "Entry");
PGPPublicKey publicKey = null;
InputStream publicKeyStream = new FileInputStream(keyRing);
// Read the key file using BouncyCastle utility class to build a collection.
PGPPublicKeyRingCollection keyRingCollection = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicKeyStream), fingerPrintCalculator);
// Iterate through the key rings to find a key that can be used for encryption
Iterator<PGPPublicKeyRing> rIt = keyRingCollection.getKeyRings();
while (publicKey == null && rIt.hasNext()) {
PGPPublicKeyRing kRing = rIt.next();
Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();
while (publicKey == null && kIt.hasNext()) {
PGPPublicKey key = kIt.next();
if (key.isEncryptionKey()) {
publicKey = key;
}
}
}
// The key store does not contain any key.
if (publicKey == null) {
throw new CryptDecryptException("Can't find public key in the key ring.");
}
// Check if the key can be used for encryption. If not throw an exception
if (!isForEncryption(publicKey)) {
throw new CryptDecryptException("KeyID " + publicKey.getKeyID() + " not flagged for encryption.");
}
if(enableDebugLog)Trace.logInfo("CryptDecryptUtil.readPublicKey", "Exit");
return publicKey;
}
示例4: PgpKeyId
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public PgpKeyId(PGPPublicKey keyId) {
this(keyId.getKeyID());
}
示例5: generateTest
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public void generateTest()
throws Exception
{
char[] passPhrase = "hello".toCharArray();
DSAParametersGenerator dsaPGen = new DSAParametersGenerator();
dsaPGen.init(512, 10, new SecureRandom());
DSAKeyPairGenerator dsaKpg = new DSAKeyPairGenerator();
dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));
//
// this takes a while as the key generator has to generate some DSA params
// before it generates the key.
//
AsymmetricCipherKeyPair dsaKp = dsaKpg.generateKeyPair();
ElGamalKeyPairGenerator elgKpg = new ElGamalKeyPairGenerator();
BigInteger g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
BigInteger p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
ElGamalParameters elParams = new ElGamalParameters(p, g);
elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));
//
// this is quicker because we are using pregenerated parameters.
//
AsymmetricCipherKeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
"test", null, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
keyRingGen.addSubKey(elgKeyPair);
PGPSecretKeyRing keyRing = keyRingGen.generateSecretKeyRing();
keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
PGPPublicKey vKey = null;
PGPPublicKey sKey = null;
Iterator it = pubRing.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey pk = (PGPPublicKey)it.next();
if (pk.isMasterKey())
{
vKey = pk;
}
else
{
sKey = pk;
}
}
Iterator sIt = sKey.getSignatures();
while (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
if (sig.getKeyID() == vKey.getKeyID()
&& sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
{
sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);
if (!sig.verifyCertification(vKey, sKey))
{
fail("failed to verify sub-key signature.");
}
}
}
}
示例6: generateSha1Test
import org.bouncycastle.openpgp.PGPPublicKey; //导入方法依赖的package包/类
public void generateSha1Test()
throws Exception
{
char[] passPhrase = "hello".toCharArray();
DSAParametersGenerator dsaPGen = new DSAParametersGenerator();
dsaPGen.init(512, 10, new SecureRandom());
DSAKeyPairGenerator dsaKpg = new DSAKeyPairGenerator();
dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));
//
// this takes a while as the key generator has to generate some DSA params
// before it generates the key.
//
AsymmetricCipherKeyPair dsaKp = dsaKpg.generateKeyPair();
ElGamalKeyPairGenerator elgKpg = new ElGamalKeyPairGenerator();
BigInteger g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
BigInteger p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
ElGamalParameters elParams = new ElGamalParameters(p, g);
elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));
//
// this is quicker because we are using pregenerated parameters.
//
AsymmetricCipherKeyPair elgKp = elgKpg.generateKeyPair();
PGPKeyPair dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
PGPKeyPair elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
PGPDigestCalculator chkSumCalc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
"test", chkSumCalc, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
keyRingGen.addSubKey(elgKeyPair);
PGPSecretKeyRing keyRing = keyRingGen.generateSecretKeyRing();
keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
PGPPublicKey vKey = null;
PGPPublicKey sKey = null;
Iterator it = pubRing.getPublicKeys();
while (it.hasNext())
{
PGPPublicKey pk = (PGPPublicKey)it.next();
if (pk.isMasterKey())
{
vKey = pk;
}
else
{
sKey = pk;
}
}
Iterator sIt = sKey.getSignatures();
while (sIt.hasNext())
{
PGPSignature sig = (PGPSignature)sIt.next();
if (sig.getKeyID() == vKey.getKeyID()
&& sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
{
sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);
if (!sig.verifyCertification(vKey, sKey))
{
fail("failed to verify sub-key signature.");
}
}
}
}