本文整理汇总了Java中org.bouncycastle.openpgp.PGPSecretKey.getKeyID方法的典型用法代码示例。如果您正苦于以下问题:Java PGPSecretKey.getKeyID方法的具体用法?Java PGPSecretKey.getKeyID怎么用?Java PGPSecretKey.getKeyID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPSecretKey
的用法示例。
在下文中一共展示了PGPSecretKey.getKeyID方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyShortId
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public static Predicate<PGPSecretKey> keyShortId ( final String keyId )
{
final long keyIdNum = Long.parseUnsignedLong ( keyId, 16 );
return new Predicate<PGPSecretKey> () {
@Override
public boolean test ( final PGPSecretKey key )
{
final long shortId = key.getKeyID () & 0xFFFFFFFFL;
if ( key.getKeyID () != keyIdNum && shortId != keyIdNum )
{
return false;
}
return true;
}
};
}
示例2: OpenPGPSecretKey
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public OpenPGPSecretKey(String keyId, InputStream secretKeyRing, char[] password) throws IOException {
PGPObjectFactory pgpObjectFactory = new BcPGPObjectFactory(PGPUtil.getDecoderStream(secretKeyRing));
for (Object it = pgpObjectFactory.nextObject(); it != null; it = pgpObjectFactory.nextObject()) {
PGPSecretKeyRing pgpSecretKeyRing = (PGPSecretKeyRing) it;
PGPSecretKey pgpSecretKey = pgpSecretKeyRing.getSecretKey();
if (keyId == null || keyId.isEmpty() || Long.valueOf(keyId, 16) == (pgpSecretKey.getKeyID() & MASK)) {
this.secretKey = pgpSecretKey;
break;
}
}
// sanity check
if (secretKey == null) {
throw new IllegalArgumentException("Secret key " + keyId + " not found");
}
this.password = password;
}
示例3: loadSecretKey
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public static PGPSecretKey loadSecretKey ( final InputStream input, final String keyId ) throws IOException, PGPException
{
final long keyIdNum = Long.parseUnsignedLong ( keyId, 16 );
final BcPGPSecretKeyRingCollection keyrings = new BcPGPSecretKeyRingCollection ( PGPUtil.getDecoderStream ( input ) );
final Iterator<?> keyRingIter = keyrings.getKeyRings ();
while ( keyRingIter.hasNext () )
{
final PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing)keyRingIter.next ();
final Iterator<?> secretKeyIterator = secretKeyRing.getSecretKeys ();
while ( secretKeyIterator.hasNext () )
{
final PGPSecretKey key = (PGPSecretKey)secretKeyIterator.next ();
if ( !key.isSigningKey () )
{
continue;
}
final long shortId = key.getKeyID () & 0xFFFFFFFFL;
if ( key.getKeyID () != keyIdNum && shortId != keyIdNum )
{
continue;
}
return key;
}
}
return null;
}
示例4: readSecretKey
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private PGPSecretKey readSecretKey(InputStream in) throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(in,
new BcKeyFingerprintCalculator());
PGPSecretKey key = null;
Iterator<PGPSecretKeyRing> it = pgpSec.getKeyRings();
while (key == null && it.hasNext()) {
PGPSecretKeyRing kRing = it.next();
Iterator<PGPSecretKey> it2 = kRing.getSecretKeys();
while (key == null && it2.hasNext()) {
PGPSecretKey k = it2.next();
if (keyId == null && k.isSigningKey()) {
key = k;
}
if (keyId != null && Long.valueOf(keyId, 16) == (k.getKeyID() & MASK)) {
key = k;
}
}
}
if (key == null) {
throw new IllegalArgumentException("Can't find encryption key"
+ (keyId != null ? " '" + keyId + "' " : " ") + "in key ring.");
}
return key;
}
示例5: getSignature
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
private KeySignature getSignature(PGPSecretKey signingKey,
SignatureType requiredSignatureType) {
final Iterator<?> signatures = publicKey.getSignatures();
while (signatures.hasNext()) {
final KeySignature signature = new KeySignature((PGPSignature) signatures.next());
if ((signature.getKeyID() == signingKey.getKeyID()) &&
(signature.getSignatureType() == requiredSignatureType)) {
return signature;
}
}
return null;
}
示例6: makeShortKey
import org.bouncycastle.openpgp.PGPSecretKey; //导入方法依赖的package包/类
public static String makeShortKey ( final PGPSecretKey key )
{
final long shortId = key.getKeyID () & 0xFFFFFFFFL;
return String.format ( "%08X", shortId );
}