本文整理汇总了Java中org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor类的典型用法代码示例。如果您正苦于以下问题:Java PBESecretKeyDecryptor类的具体用法?Java PBESecretKeyDecryptor怎么用?Java PBESecretKeyDecryptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PBESecretKeyDecryptor类属于org.bouncycastle.openpgp.operator包,在下文中一共展示了PBESecretKeyDecryptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyWithNewPassword
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
/**
* Return a copy of the passed in secret key ring, with the private keys (where present) associated with the master key and sub keys
* are encrypted using a new password and the passed in algorithm.
*
* @param ring the PGPSecretKeyRing to be copied.
* @param oldKeyDecryptor the current decryptor based on the current password for key.
* @param newKeyEncryptor a new encryptor based on a new password for encrypting the secret key material.
* @return the updated key ring.
*/
public static PGPSecretKeyRing copyWithNewPassword(
PGPSecretKeyRing ring,
PBESecretKeyDecryptor oldKeyDecryptor,
PBESecretKeyEncryptor newKeyEncryptor)
throws PGPException
{
List newKeys = new ArrayList(ring.keys.size());
for (Iterator keys = ring.getSecretKeys(); keys.hasNext();)
{
PGPSecretKey key = (PGPSecretKey)keys.next();
if (key.isPrivateKeyEmpty())
{
newKeys.add(key);
}
else
{
newKeys.add(PGPSecretKey.copyWithNewPassword(key, oldKeyDecryptor, newKeyEncryptor));
}
}
return new PGPSecretKeyRing(newKeys, ring.extraPubKeys);
}
示例2: build
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
public PBESecretKeyDecryptor build(char[] passPhrase)
{
return new PBESecretKeyDecryptor(passPhrase, calculatorProvider)
{
public byte[] recoverKeyData(int encAlgorithm, byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen)
throws PGPException
{
try
{
BufferedBlockCipher c = BcUtil.createSymmetricKeyWrapper(false, BcImplProvider.createBlockCipher(encAlgorithm), key, iv);
byte[] out = new byte[keyLen];
int outLen = c.processBytes(keyData, keyOff, keyLen, out, 0);
outLen += c.doFinal(out, outLen);
return out;
}
catch (InvalidCipherTextException e)
{
throw new PGPException("decryption failed: " + e.getMessage(), e);
}
}
};
}
示例3: copySecretKeyRingWithNewPassword
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
public static PGPSecretKeyRing copySecretKeyRingWithNewPassword(byte[] privateKeyData,
char[] oldPassphrase, char[] newPassphrase) throws PGPException, IOException, KonException {
// load the secret key ring
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, FP_CALC);
PGPDigestCalculatorProvider calcProv = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProv)
.setProvider(PGPUtils.PROVIDER)
.build(oldPassphrase);
PGPDigestCalculator calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA256);
PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, calc)
.setProvider(PROVIDER).build(newPassphrase);
try {
return PGPSecretKeyRing.copyWithNewPassword(secRing, decryptor, encryptor);
} catch (PGPException ex) {
// treat this special, cause most like the decryption password was wrong
throw new KonException(KonException.Error.CHANGE_PASS_COPY, ex);
}
}
示例4: extractPrivateKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
private static PGPPrivateKey extractPrivateKey(PGPSecretKey pgpSecKey, char[] passPhrase)
throws PGPException {
PGPPrivateKey privateKey = null;
BcPGPDigestCalculatorProvider calculatorProvider = new BcPGPDigestCalculatorProvider();
BcPBESecretKeyDecryptorBuilder secretKeyDecryptorBuilder = new BcPBESecretKeyDecryptorBuilder(
calculatorProvider);
PBESecretKeyDecryptor pBESecretKeyDecryptor = secretKeyDecryptorBuilder.build(passPhrase);
try {
privateKey = pgpSecKey.extractPrivateKey(pBESecretKeyDecryptor);
} catch (PGPException e) {
throw new PGPException("invalid privateKey passPhrase: " + String.valueOf(passPhrase),
e);
}
return privateKey;
}
示例5: createPrivateKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
private PGPPrivateKey createPrivateKey(PGPSecretKey secretKey, String password) {
try {
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(password.toCharArray());
return secretKey.extractPrivateKey(decryptor);
} catch (PGPException e) {
throw new UncheckedException(e);
}
}
示例6: doInBackground
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
@Override
protected Void doInBackground() throws Exception
{
Main.logger.info("Neue Schlüssel werden generiert...");
PGPKeyRingGenerator pkg = RSAGen.generateKeyRingGenerator(mail, pass, this);
PGPPublicKeyRing pkr = pkg.generatePublicKeyRing();
PGPSecretKeyRing skr = pkg.generateSecretKeyRing();
Main.psk = skr.getSecretKey();
Iterator<PGPPublicKey> rIt = pkr.getPublicKeys();
// Sucht den Verschlüsselungsschlüssel
while (Main.ppk == null && rIt.hasNext())
{
PGPPublicKey temp_key = rIt.next();
if (temp_key.isEncryptionKey())
{
Main.ppk = temp_key;
break;
}
}
PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pass);
Main.pprk = Main.psk.extractPrivateKey(secretKeyDecryptor);
setProgress(90);
// Speichern der Schlüssel
PGPSecretKeyRing pskr = pkg.generateSecretKeyRing();
ArmoredOutputStream secout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.secKey)));
// Geheimer Schlüssel
pskr.encode(secout);
secout.close();
ArmoredOutputStream pubout = new ArmoredOutputStream(
new BufferedOutputStream(new FileOutputStream(Main.pubKey)));
pkr.encode(pubout);
pubout.close();
setProgress(100);
return null;
}
示例7: buildDecryptor
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
/**
* Builds a secret key decryptor for the specified passphrase.
*/
protected PBESecretKeyDecryptor buildDecryptor(String passphrase) {
char[] chars = !Util.isEmpty(passphrase) ?
passphrase.toCharArray() : new char[0];
return new BcPBESecretKeyDecryptorBuilder(
new BcPGPDigestCalculatorProvider()).build(chars);
}
示例8: BcPrivateKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
BcPrivateKey(String armoredKeyString, char[] passphrase) throws PGPKeyInitialisationException {
try {
PGPSecretKeyRing secKeyRing = new PGPSecretKeyRing(
new ArmoredInputStream(new ByteArrayInputStream(armoredKeyString.getBytes(StandardCharsets.US_ASCII))),
new BcKeyFingerprintCalculator());
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider())
.build(passphrase);
ImmutableMap.Builder<Long, PGPPrivateKey> builder = ImmutableMap.builder();
List<PGPPublicKey> pubKeys = new ArrayList<>(2);
for (Iterator iterator = secKeyRing.getSecretKeys(); iterator.hasNext(); ) {
PGPSecretKey secretKey = (PGPSecretKey) iterator.next();
PGPPrivateKey privateKey = secretKey.extractPrivateKey(decryptor);
builder.put(privateKey.getKeyID(), privateKey);
pubKeys.add(secretKey.getPublicKey());
}
this.secretKey = secKeyRing.getSecretKey();
this.privateKeys = builder.build();
this.privateKey = this.secretKey.extractPrivateKey(decryptor);
if (pubKeys.size() >= 2) {
this.publicKey = new BcPublicKey(pubKeys.get(0), pubKeys.get(1));
} else {
this.publicKey = new BcPublicKey(pubKeys.get(0), pubKeys.get(0));
}
} catch (PGPException | RuntimeException | IOException e) {
throw new PGPKeyInitialisationException("Error instantiating a private key", e);
}
checkNotNull(this.secretKey);
checkNotNull(this.privateKey);
this.fingerprint = BcPublicKey.hexFingerprint(secretKey.getPublicKey());
}
示例9: findPrivateKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
/**
* Get private key using the given passphrase
* @param pgpSecKey The secret key
* @param pass passphrase to decrypt secret key with
* @return Private key
* @throws PGPException
*/
private PGPPrivateKey findPrivateKey(PGPSecretKey pgpSecKey, char[] pass)
throws PGPException {
if (pgpSecKey == null) return null;
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
return pgpSecKey.extractPrivateKey(decryptor);
}
示例10: findPrivateKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
/**
* read the private key from the given secret key
*
* @param pgpSecretKey
* the secret key
* @param password
* the password to unlock the private key
* @return the unlocked private key
* @throws PGPException
*/
protected PGPPrivateKey findPrivateKey(PGPSecretKey pgpSecretKey, String password) throws PGPException {
LOGGER.trace("findPrivateKey(PGPSecretKey, String)");
LOGGER.trace("Secret Key: {}, Password: {}", pgpSecretKey == null ? "not set" : "set", password == null ? "not set" : "********");
PGPPrivateKey result = null;
PBESecretKeyDecryptor pbeSecretKeyDecryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(password.toCharArray());
LOGGER.info("Extracting private key");
result = pgpSecretKey.extractPrivateKey(pbeSecretKeyDecryptor);
if( result == null && LOGGER.isErrorEnabled() ) {
LOGGER.error("No private key could be extracted");
}
return result;
}
示例11: findSecretKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的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);
}
示例12: findSecretKey
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的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);
}
示例13: getPgpPrivateKeyOrFail
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
private static PGPPrivateKey getPgpPrivateKeyOrFail(final long keyId, final char[] passphrase) throws IOException, PGPException {
final PGPSecretKey secretKey = getPgpSecretKeyOrFail(keyId);
final PGPDigestCalculatorProvider calculatorProvider = new BcPGPDigestCalculatorProvider();
final BcPBESecretKeyDecryptorBuilder secretKeyDecryptorBuilder = new BcPBESecretKeyDecryptorBuilder(calculatorProvider);
final PBESecretKeyDecryptor secretKeyDecryptor = secretKeyDecryptorBuilder.build(passphrase);
final PGPPrivateKey privateKey = secretKey.extractPrivateKey(secretKeyDecryptor);
return privateKey;
}
示例14: OpenPGPSignature
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
public OpenPGPSignature(OpenPGPSecretKey key) throws PGPException {
PGPDigestCalculatorProvider pgpDigestCalculator = new JcaPGPDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor pbeSecretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(pgpDigestCalculator).setProvider(BouncyCastleProvider.PROVIDER_NAME).build(key.getPassword());
JcaPGPContentSignerBuilder pgpContentSigner = new JcaPGPContentSignerBuilder(key.getSecretKey().getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(BouncyCastleProvider.PROVIDER_NAME).setDigestProvider(BouncyCastleProvider.PROVIDER_NAME);
signature = new PGPSignatureGenerator(pgpContentSigner);
PGPPrivateKey privateKey = key.getSecretKey().extractPrivateKey(pbeSecretKeyDecryptor);
signature.init(PGPSignature.BINARY_DOCUMENT, privateKey);
}
示例15: test_key
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; //导入依赖的package包/类
public void test_key(BigInteger keyId, String passphrase)
throws Exception
{
PGPSecretKeyRingCollection secretKeyRing = loadSecretKeyCollection("secring.gpg");
PGPSecretKeyRing secretKey = secretKeyRing.getSecretKeyRing(keyId.longValue());
assertNotNull("Could not locate secret keyring with Id=" + keyId.toString(16), secretKey);
PGPSecretKey key = secretKey.getSecretKey();
assertNotNull("Could not locate secret key!", key);
try
{
PGPDigestCalculatorProvider calcProvider = new JcaPGPDigestCalculatorProviderBuilder()
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(calcProvider)
.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(passphrase.toCharArray());
PGPPrivateKey privateKey = key.extractPrivateKey(decryptor);
assertTrue(privateKey.getKeyID() == keyId.longValue());
}
catch (PGPException e)
{
throw new PGPException("Password incorrect!", e);
}
// all fine!
}