本文整理汇总了Java中org.bouncycastle.openpgp.PGPSecretKeyRing类的典型用法代码示例。如果您正苦于以下问题:Java PGPSecretKeyRing类的具体用法?Java PGPSecretKeyRing怎么用?Java PGPSecretKeyRing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PGPSecretKeyRing类属于org.bouncycastle.openpgp包,在下文中一共展示了PGPSecretKeyRing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
static PGPSecretKey readSecretKey() throws Exception {
InputStream input = new ByteArrayInputStream(getSecKeyRing());
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input),
new BcKeyFingerprintCalculator());
@SuppressWarnings("rawtypes")
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
@SuppressWarnings("rawtypes")
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext()) {
PGPSecretKey key = (PGPSecretKey) keyIter.next();
if (key.isSigningKey()) {
return key;
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
示例2: getSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
static PGPSecretKey getSecretKey(String privateKeyData) throws IOException, PGPException {
PGPPrivateKey privKey = null;
try (InputStream privStream = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData.getBytes("UTF-8")))) {
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privStream), new JcaKeyFingerprintCalculator());
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext()) {
PGPSecretKey key = (PGPSecretKey)keyIter.next();
if (key.isSigningKey()) {
return key;
}
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
示例3: load
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/**
* Loads all keys from the specified input stream,
* and adds them to this ring's existing list of keys.
*/
public List<Key> load(InputStream stream) throws IOException, PGPException {
ArrayList<Key> keys = new ArrayList<Key>();
Iterator packets = parse(unarmor(stream));
while (packets.hasNext()) {
Object packet = packets.next();
if (packet instanceof PGPSecretKeyRing)
keys.add(newKey((PGPSecretKeyRing) packet));
else if (packet instanceof PGPPublicKeyRing)
keys.add(newKey((PGPPublicKeyRing) packet));
}
this.keys.addAll(keys);
return keys;
}
示例4: checkSecretKeyRingWithPersonalCertificate
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private void checkSecretKeyRingWithPersonalCertificate(byte[] keyRing)
throws Exception
{
PGPSecretKeyRingCollection secCol = new PGPSecretKeyRingCollection(keyRing, new BcKeyFingerprintCalculator());
int count = 0;
for (Iterator rIt = secCol.getKeyRings(); rIt.hasNext();)
{
PGPSecretKeyRing ring = (PGPSecretKeyRing)rIt.next();
for (Iterator it = ring.getExtraPublicKeys(); it.hasNext();)
{
it.next();
count++;
}
}
if (count != 1)
{
fail("personal certificate data subkey not found - count = " + count);
}
}
示例5: readSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static PGPSecretKey readSecretKey( PGPSecretKeyRing keyRing ) throws PGPException
{
try
{
Iterator keyIter = keyRing.getSecretKeys();
while ( keyIter.hasNext() )
{
PGPSecretKey key = ( PGPSecretKey ) keyIter.next();
if ( key.isSigningKey() )
{
return key;
}
}
}
catch ( Exception e )
{
LOG.error( e.getMessage() );
}
return null;
}
示例6: testVerifySignature
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Test
public void testVerifySignature() throws Exception
{
PGPPublicKey encryptingKey =
PGPEncryptionUtil.findPublicKeyByFingerprint( findFile( PUBLIC_KEYRING ), PUBLIC_KEY_FINGERPRINT );
PGPSecretKeyRing secretKeys = PGPKeyUtil.readSecretKeyRing( findFile( SECRET_KEYRING ) );
byte[] signedAndEncryptedMessage = PGPEncryptionUtil
.signAndEncrypt( MESSAGE.getBytes(), secretKeys.getSecretKey(), SECRET_PWD, encryptingKey, true );
ContentAndSignatures contentAndSignatures =
PGPEncryptionUtil.decryptAndReturnSignatures( signedAndEncryptedMessage, secretKeys, SECRET_PWD );
assertTrue( PGPEncryptionUtil.verifySignature( contentAndSignatures, secretKeys.getPublicKey() ) );
}
示例7: readSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private static PGPSecretKey readSecretKey( InputStream is ) throws IOException, PGPException
{
PGPSecretKeyRingCollection pgpSec =
new PGPSecretKeyRingCollection( PGPUtil.getDecoderStream( is ), new JcaKeyFingerprintCalculator() );
Iterator keyRingIter = pgpSec.getKeyRings();
while ( keyRingIter.hasNext() )
{
PGPSecretKeyRing keyRing = ( PGPSecretKeyRing ) keyRingIter.next();
Iterator keyIter = keyRing.getSecretKeys();
while ( keyIter.hasNext() )
{
PGPSecretKey key = ( PGPSecretKey ) keyIter.next();
if ( key.isSigningKey() )
{
return key;
}
}
}
throw new IllegalArgumentException( "Can't find signing key in key ring." );
}
示例8: signKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Override
public PGPPublicKeyRing signKey( PGPSecretKeyRing sourceSecRing, PGPPublicKeyRing targetPubRing, int trustLevel )
{
try
{
String sigId = PGPKeyUtil.encodeNumericKeyId( targetPubRing.getPublicKey().getKeyID() );
targetPubRing = encryptionTool.signPublicKey( targetPubRing, sigId, sourceSecRing.getSecretKey(), "" );
}
catch ( Exception ignored )
{
//ignore
}
return targetPubRing;
}
示例9: signPublicKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Override
public String signPublicKey( String sourceIdentityId, String keyText, int trustLevel )
{
String keyStr = "";
try
{
PGPPublicKeyRing targetPubRing = PGPKeyUtil.readPublicKeyRing( keyText );
PGPSecretKeyRing sourceSecRing = getSecretKeyRing( sourceIdentityId );
targetPubRing = signKey( sourceSecRing, targetPubRing, trustLevel );
keyStr = encryptionTool.armorByteArrayToString( targetPubRing.getEncoded() );
}
catch ( Exception ex )
{
LOG.error( "**** Error !!! Error signing key, IdentityId: " + sourceIdentityId, ex );
}
return keyStr;
}
示例10: saveSecretKeyRing
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Override
public void saveSecretKeyRing( String identityId, int type, PGPSecretKeyRing secretKeyRing )
{
try
{
PGPPublicKey publicKey = secretKeyRing.getPublicKey();
if ( publicKey != null )
{
// Store secretKey
String fingerprint = PGPKeyUtil.getFingerprint( publicKey.getFingerprint() );
String pwd = keyData.getSecretKeyringPwd();
//*******************
securityDataService.saveSecretKeyData( fingerprint, secretKeyRing.getEncoded(), pwd, type );
securityDataService.saveKeyData( identityId, fingerprint, "", type );
//*******************
}
}
catch ( Exception ex )
{
LOG.error( " ******** Error storing Public key:" + ex.toString(), ex );
}
}
示例11: getSecretKeyRingByFingerprint
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Override
public PGPSecretKeyRing getSecretKeyRingByFingerprint( String fingerprint )
{
try
{
SecretKeyStore secData = securityDataService.getSecretKeyData( fingerprint );
if ( secData != null )
{
return PGPKeyUtil.readSecretKeyRing( secData.getData() );
}
else
{
return null;
}
}
catch ( PGPException e )
{
return null;
}
}
示例12: createEnvironmentKeyPair
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
PGPSecretKeyRing createEnvironmentKeyPair( EnvironmentId envId ) throws EnvironmentCreationException
{
KeyManager keyManager = securityManager.getKeyManager();
String pairId = envId.getId();
try
{
KeyPair keyPair = keyManager.generateKeyPair( pairId, false );
//******Create PEK *****************************************************************
PGPSecretKeyRing secRing = pgpKeyUtil.getSecretKeyRing( keyPair.getSecKeyring() );
PGPPublicKeyRing pubRing = pgpKeyUtil.getPublicKeyRing( keyPair.getPubKeyring() );
//***************Save Keys *********************************************************
keyManager.saveSecretKeyRing( pairId, SecurityKeyType.ENVIRONMENT_KEY.getId(), secRing );
keyManager.savePublicKeyRing( pairId, SecurityKeyType.ENVIRONMENT_KEY.getId(), pubRing );
return secRing;
}
catch ( PGPException ex )
{
throw new EnvironmentCreationException( ex );
}
}
示例13: testCreateEnvironmentKeyPair
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Test
public void testCreateEnvironmentKeyPair() throws Exception
{
KeyPair keyPair = mock( KeyPair.class );
doReturn( keyPair ).when( keyManager ).generateKeyPair( TestHelper.ENV_ID, false );
PGPSecretKeyRing secRing = mock( PGPSecretKeyRing.class );
PGPPublicKeyRing pubRing = mock( PGPPublicKeyRing.class );
doReturn( secRing ).when( pgpKeyUtil ).getSecretKeyRing( any( byte[].class ) );
doReturn( pubRing ).when( pgpKeyUtil ).getPublicKeyRing( any( byte[].class ) );
environmentManager.createEnvironmentKeyPair( TestHelper.ENVIRONMENT_ID );
verify( keyManager ).saveSecretKeyRing( TestHelper.ENV_ID, SecurityKeyType.ENVIRONMENT_KEY.getId(), secRing );
verify( keyManager ).savePublicKeyRing( TestHelper.ENV_ID, SecurityKeyType.ENVIRONMENT_KEY.getId(), pubRing );
}
示例14: readSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private PGPSecretKey readSecretKey() throws IOException, PGPException {
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(new ByteArrayInputStream(config.keypair.getBytes())),
new JcaKeyFingerprintCalculator());
Iterator<PGPSecretKeyRing> keyRings = pgpSec.getKeyRings();
while (keyRings.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRings.next();
Iterator<PGPSecretKey> keys = keyRing.getSecretKeys();
while (keys.hasNext()) {
PGPSecretKey key = (PGPSecretKey) keys.next();
if (key.isSigningKey()) {
return key;
}
}
}
throw new IllegalStateException("Can't find signing key in key ring.");
}
示例15: extractSecrectKeyRings
import org.bouncycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private static List<PGPSecretKeyRing> extractSecrectKeyRings(InputStream inputStream) {
InputStream decodedInput;
try {
decodedInput = PGPUtil.getDecoderStream(inputStream);
} catch (final IOException e) {
throw JkUtilsThrowable.unchecked(e);
}
final KeyFingerPrintCalculator fingerPrintCalculator = new JcaKeyFingerprintCalculator();
final InnerPGPObjectFactory pgpFact = new InnerPGPObjectFactory(decodedInput,
fingerPrintCalculator);
PGPSecretKeyRing secKeyRing;
final List<PGPSecretKeyRing> result = new LinkedList<>();
while ((secKeyRing = pgpFact.nextSecretKey()) != null) {
result.add(secKeyRing);
}
return result;
}