本文整理汇总了Java中org.bouncycastle.openpgp.PGPSecretKeyRingCollection.getSecretKey方法的典型用法代码示例。如果您正苦于以下问题:Java PGPSecretKeyRingCollection.getSecretKey方法的具体用法?Java PGPSecretKeyRingCollection.getSecretKey怎么用?Java PGPSecretKeyRingCollection.getSecretKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openpgp.PGPSecretKeyRingCollection
的用法示例。
在下文中一共展示了PGPSecretKeyRingCollection.getSecretKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrivateKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
* ***********************************************
*/
private static PGPPrivateKey getPrivateKey( final PGPSecretKeyRingCollection keys, final long id,
final String secretPwd )
{
try
{
final PGPSecretKey key = keys.getSecretKey( id );
if ( key != null )
{
return key.extractPrivateKey( new JcePBESecretKeyDecryptorBuilder().setProvider( provider )
.build( secretPwd.toCharArray() ) );
}
}
catch ( final Exception e )
{
// Don't print the passphrase but do print null if thats what it was
final String passphraseMessage = ( secretPwd == null ) ? "null" : "supplied";
LOG.warn( "Unable to extract key " + id + " using " + passphraseMessage + " passphrase: {}",
e.getMessage() );
}
return null;
}
示例2: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
* Search a secret key ring collection for a secret key corresponding to keyID if it
* exists.
*
* @param pgpSec a secret key ring collection.
* @param keyID keyID we want.
* @param pass passphrase to decrypt secret key with.
* @return
* @throws PGPException
* @throws NoSuchProviderException
*/
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
throws PGPException, NoSuchProviderException
{
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null)
{
return null;
}
return pgpSecKey.extractPrivateKey(pass, "BC");
}
示例3: decrypt
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
public static final byte[] decrypt(File privring, long keyid, char[] pw, byte[] in){
if(!privring.exists() || !privring.isFile()) return null;
try {
byte[] ret = null;
FileInputStream fis = new FileInputStream(privring);
InputStream is = PGPUtil.getDecoderStream(fis);
PGPSecretKeyRingCollection ring = new PGPSecretKeyRingCollection(is);
PGPSecretKey seckey = ring.getSecretKey(keyid);
if(seckey.isMasterKey()) {
System.err.println("Someone tried to use a non-encryption key. This should never happen.");
return null;
}
PrivateKey key = new JcaPGPKeyConverter().getPrivateKey(
seckey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pw)
)
);
Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, key);
ret = cipher.doFinal(in);
is.close();
fis.close();
return ret;
} catch (Exception e) {
System.err.println(e.getLocalizedMessage());
return null;
}
}
示例4: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
private static PGPPrivateKey findSecretKey(
PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
throws PGPException, NoSuchProviderException {
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null) {
return null;
}
final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(
new BcPGPDigestCalculatorProvider()).build(pass);
return pgpSecKey.extractPrivateKey(decryptor);
}
示例5: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
public static PGPPrivateKey findSecretKey(final InputStream keyIn, final long keyID, final char[] pass) throws IOException, PGPException {
final PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyIn), new BcKeyFingerprintCalculator());
final PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null) return null;
final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
return pgpSecKey.extractPrivateKey(decryptor);
}
示例6: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
* Private util function that finds the private key from keyring collection based on keyId and passPhrase
* @param pgpSec keyring collection
* @param keyID keyID for this encryption file
* @param passPhrase passPhrase for this encryption file
* @throws PGPException
*/
private PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, String passPhrase)
throws PGPException {
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null) {
return null;
}
return pgpSecKey.extractPrivateKey(
new JcePBESecretKeyDecryptorBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(passPhrase.toCharArray()));
}
示例7: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
* Search a secret key ring collection for a secret key corresponding to keyID if it
* exists.
*
* @param pgpSec a secret key ring collection.
* @param keyID keyID we want.
* @param pass passphrase to decrypt secret key with.
* @return the private key.
* @throws PGPException
* @throws NoSuchProviderException
*/
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
throws PGPException, NoSuchProviderException
{
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null)
{
return null;
}
return pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
}
示例8: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
protected static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID,
char[] pass) throws PGPException, NoSuchProviderException {
PGPPrivateKey privateKey = null;
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null) {
return null;
}
privateKey = extractPrivateKey(pgpSecKey, pass);
return privateKey;
}
示例9: findSecretKey
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; //导入方法依赖的package包/类
/**
* Search a secret key ring collection for a secret key corresponding to
* keyID if it exists.
*
* @param pgpSec
* a secret key ring collection.
* @param keyID
* keyID we want.
* @param pass
* passphrase to decrypt secret key with.
* @return the private key.
* @throws PGPException
* @throws NoSuchProviderException
*/
static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
throws PGPException, NoSuchProviderException
{
PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
if (pgpSecKey == null)
{
return null;
}
return pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
}