本文整理汇总了Java中org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcaPGPDigestCalculatorProviderBuilder类的具体用法?Java JcaPGPDigestCalculatorProviderBuilder怎么用?Java JcaPGPDigestCalculatorProviderBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JcaPGPDigestCalculatorProviderBuilder类属于org.bouncycastle.openpgp.operator.jcajce包,在下文中一共展示了JcaPGPDigestCalculatorProviderBuilder类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPGPKeyRingGenerator
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
*
* @param dsaKeyPair - the generated DSA key pair
* @param elGamalKeyPair - the generated El Gamal key pair
* @param identity - the given identity of the key pair ring
* @param passphrase - the secret pass phrase to protect the key pair
* @return a PGP Key Ring Generate with the El Gamal key pair added as sub key
* @throws Exception
*/
public static final PGPKeyRingGenerator createPGPKeyRingGenerator(KeyPair dsaKeyPair, KeyPair elGamalKeyPair, String identity, char[] passphrase) throws Exception {
PGPKeyPair dsaPgpKeyPair = new JcaPGPKeyPair(PGPPublicKey.DSA, dsaKeyPair, new Date());
PGPKeyPair elGamalPgpKeyPair = new JcaPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elGamalKeyPair, new Date());
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(
PGPSignature.POSITIVE_CERTIFICATION,
dsaPgpKeyPair,
identity,
sha1Calc,
null,
null,
new JcaPGPContentSignerBuilder(dsaPgpKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc).setProvider("BC").build(passphrase)
);
keyRingGen.addSubKey(elGamalPgpKeyPair);
return keyRingGen;
}
示例2: serializeKeyPair
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Serialize a PGPKeyPair
*
* <p>Use this to serialize a PGPPrivateKey as well (pairing it with the corresponding
* PGPPublicKey), as private keys can't be serialized on their own.
*/
public static byte[] serializeKeyPair(PGPKeyPair keyPair) throws IOException, PGPException {
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
// NOTE: We have to close the ArmoredOutputStream before calling the underlying OutputStream's
// "toByteArray". Failing to do so would result in a truncated serialization as we took the
// byte array before the ArmoredOutputStream wrote all the data.
//
// Even "flushing" the ArmoredOutputStream isn't enough - as there are parts that are only
// written by the ArmoredOutputStream when it is closed: the "-----END PGP PRIVATE KEY
// BLOCK-----" (or similar) footer.
try (ArmoredOutputStream out = new ArmoredOutputStream(byteStream)) {
new PGPSecretKey(
keyPair.getPrivateKey(),
keyPair.getPublicKey(),
new JcaPGPDigestCalculatorProviderBuilder()
.setProvider("BC")
.build()
.get(HashAlgorithmTags.SHA256),
true,
null).encode(out);
}
return byteStream.toByteArray();
}
}
示例3: PGPSecretKey
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* @deprecated use method taking PBESecretKeyEncryptor
*/
public PGPSecretKey(
int certificationLevel,
PGPKeyPair keyPair,
String id,
int encAlgorithm,
char[] passPhrase,
boolean useSHA1,
PGPSignatureSubpacketVector hashedPcks,
PGPSignatureSubpacketVector unhashedPcks,
SecureRandom rand,
Provider provider)
throws PGPException
{
this(keyPair.getPrivateKey(), certifiedPublicKey(certificationLevel, keyPair, id, hashedPcks, unhashedPcks, new JcaPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(provider)), convertSHA1Flag(useSHA1), true, new JcePBESecretKeyEncryptorBuilder(encAlgorithm, new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1)).setProvider(provider).setSecureRandom(rand).build(passPhrase));
}
示例4: copySecretKeyRingWithNewPassword
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的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);
}
}
示例5: OpenPGPSignature
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的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);
}
示例6: addMethod
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Add a PBE encryption method to the encrypted object.
*
* @param passPhrase passphrase to use to generate key.
* @param s2kDigest digest algorithm to use for S2K calculation
* @throws NoSuchProviderException
* @throws PGPException
* @deprecated use addMethod that takes PGPKeyEncryptionMethodGenerator
*/
public void addMethod(
char[] passPhrase,
int s2kDigest)
throws NoSuchProviderException, PGPException
{
if (defProvider == null)
{
defProvider = new BouncyCastleProvider();
}
addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase, new JcaPGPDigestCalculatorProviderBuilder().setProvider(defProvider).build().get(s2kDigest)).setProvider(defProvider).setSecureRandom(rand));
}
示例7: test_key
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的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!
}
示例8: convertSHA1Flag
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
private static PGPDigestCalculator convertSHA1Flag(boolean useSHA1)
throws PGPException
{
return useSHA1 ? new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1) : null;
}
示例9: generateAndSign
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
private void generateAndSign()
throws Exception
{
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC");
keyGen.initialize(new ECGenParameterSpec("P-256"));
KeyPair kpSign = keyGen.generateKeyPair();
PGPKeyPair ecdsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.ECDSA, kpSign, new Date());
//
// try a signature
//
PGPSignatureGenerator signGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(PGPPublicKey.ECDSA, HashAlgorithmTags.SHA256).setProvider("BC"));
signGen.init(PGPSignature.BINARY_DOCUMENT, ecdsaKeyPair.getPrivateKey());
signGen.update("hello world!".getBytes());
PGPSignature sig = signGen.generate();
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider("BC"), ecdsaKeyPair.getPublicKey());
sig.update("hello world!".getBytes());
if (!sig.verify())
{
fail("signature failed to verify!");
}
//
// generate a key ring
//
char[] passPhrase = "test".toCharArray();
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, ecdsaKeyPair,
"[email protected]", sha1Calc, null, null, new JcaPGPContentSignerBuilder(ecdsaKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc).setProvider("BC").build(passPhrase));
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
PGPSecretKeyRing secRing = keyRingGen.generateSecretKeyRing();
KeyFingerPrintCalculator fingerCalc = new JcaKeyFingerprintCalculator();
PGPPublicKeyRing pubRingEnc = new PGPPublicKeyRing(pubRing.getEncoded(), fingerCalc);
if (!Arrays.areEqual(pubRing.getEncoded(), pubRingEnc.getEncoded()))
{
fail("public key ring encoding failed");
}
PGPSecretKeyRing secRingEnc = new PGPSecretKeyRing(secRing.getEncoded(), fingerCalc);
if (!Arrays.areEqual(secRing.getEncoded(), secRingEnc.getEncoded()))
{
fail("secret key ring encoding failed");
}
}
示例10: generate
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
private void generate()
throws Exception
{
//
// Generate a master key
//
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC");
keyGen.initialize(new ECGenParameterSpec("P-256"));
KeyPair kpSign = keyGen.generateKeyPair();
PGPKeyPair ecdsaKeyPair = new JcaPGPKeyPair(PGPPublicKey.ECDSA, kpSign, new Date());
//
// Generate an encryption key
//
keyGen = KeyPairGenerator.getInstance("ECDH", "BC");
keyGen.initialize(new ECGenParameterSpec("P-256"));
KeyPair kpEnc = keyGen.generateKeyPair();
PGPKeyPair ecdhKeyPair = new JcaPGPKeyPair(PGPPublicKey.ECDH, kpEnc, new Date());
//
// generate a key ring
//
char[] passPhrase = "test".toCharArray();
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, ecdsaKeyPair,
"[email protected]", sha1Calc, null, null,
new JcaPGPContentSignerBuilder(ecdsaKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc).setProvider("BC").build(passPhrase));
keyRingGen.addSubKey(ecdhKeyPair);
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
// TODO: add check of KdfParameters
doBasicKeyRingCheck(pubRing);
PGPSecretKeyRing secRing = keyRingGen.generateSecretKeyRing();
KeyFingerPrintCalculator fingerCalc = new JcaKeyFingerprintCalculator();
PGPPublicKeyRing pubRingEnc = new PGPPublicKeyRing(pubRing.getEncoded(), fingerCalc);
if (!Arrays.areEqual(pubRing.getEncoded(), pubRingEnc.getEncoded()))
{
fail("public key ring encoding failed");
}
PGPSecretKeyRing secRingEnc = new PGPSecretKeyRing(secRing.getEncoded(), fingerCalc);
if (!Arrays.areEqual(secRing.getEncoded(), secRingEnc.getEncoded()))
{
fail("secret key ring encoding failed");
}
}
示例11: generate
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Generates a new {@link KeySet}.
*
* @param userId the user ID, in {@code First Last <[email protected]>} format
* @param passphrase the user's passphrase
* @return a key set for the user
* @throws CryptographicException if there was an error generating the key set
*/
public KeySet generate(String userId, char[] passphrase) throws CryptographicException {
try {
final Date timestamp = new Date();
final Future<AsymmetricCipherKeyPair> masterKeyPair =
executor.submit(new Callable<AsymmetricCipherKeyPair>() {
@Override
public AsymmetricCipherKeyPair call() throws Exception {
return masterKeyGenerator.generate(random);
}
});
final Future<AsymmetricCipherKeyPair> subKeyPair =
executor.submit(new Callable<AsymmetricCipherKeyPair>() {
@Override
public AsymmetricCipherKeyPair call() throws Exception {
return subKeyGenerator.generate(random);
}
});
final BcPGPKeyPair masterPGPKeyPair =
new BcPGPKeyPair(masterKeyGenerator.getAlgorithm().value(),
masterKeyPair.get(),
timestamp);
final PGPDigestCalculator calculator =
new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
final PGPContentSignerBuilder signer =
new JcaPGPContentSignerBuilder(masterPGPKeyPair.getPublicKey().getAlgorithm(),
HashAlgorithmTags.SHA1)
.setSecureRandom(random);
final PBESecretKeyEncryptor encryptor =
new JcePBESecretKeyEncryptorBuilder(keyEncryptionAlgorithm.value())
.setSecureRandom(random)
.build(passphrase);
final PGPKeyRingGenerator generator =
new PGPKeyRingGenerator(SignatureType.POSITIVE_CERTIFICATION.value(),
masterPGPKeyPair,
userId,
calculator,
generateMasterKeySettings(),
null, // only use hashed packets
signer,
encryptor);
final BcPGPKeyPair subPGPKeyPair =
new BcPGPKeyPair(subKeyGenerator.getAlgorithm().value(),
subKeyPair.get(),
timestamp);
generator
.addSubKey(subPGPKeyPair, generateSubKeySettings(), null); // likewise, use hashed packets
return new KeySet(generator.generateSecretKeyRing());
} catch (PGPException | InterruptedException | ExecutionException e) {
throw new CryptographicException(e);
}
}
示例12: extractPrivateKey
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Extract a PGPPrivate key from the SecretKey's encrypted contents.
*
* @param passPhrase
* @param provider
* @return PGPPrivateKey
* @throws PGPException
* @deprecated use method that takes a PBESecretKeyDecryptor
*/
public PGPPrivateKey extractPrivateKey(
char[] passPhrase,
Provider provider)
throws PGPException
{
return extractPrivateKey(new JcePBESecretKeyDecryptorBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build()).setProvider(provider).build(passPhrase));
}
示例13: copyWithNewPassword
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Return a copy of the passed in secret key, encrypted using a new
* password and the passed in algorithm.
*
* @param key the PGPSecretKey to be copied.
* @param oldPassPhrase the current password for key.
* @param newPassPhrase the new password for the key.
* @param newEncAlgorithm the algorithm to be used for the encryption.
* @param rand source of randomness.
* @param provider the provider to use
* @deprecated use method taking PBESecretKeyDecryptor and PBESecretKeyEncryptor
*/
public static PGPSecretKey copyWithNewPassword(
PGPSecretKey key,
char[] oldPassPhrase,
char[] newPassPhrase,
int newEncAlgorithm,
SecureRandom rand,
Provider provider)
throws PGPException
{
return copyWithNewPassword(key, new JcePBESecretKeyDecryptorBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build()).setProvider(provider).build(oldPassPhrase), new JcePBESecretKeyEncryptorBuilder(newEncAlgorithm).setProvider(provider).setSecureRandom(rand).build(newPassPhrase));
}
示例14: getDataStream
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; //导入依赖的package包/类
/**
* Return the decrypted input stream, using the passed in passPhrase.
*
* @param passPhrase
* @param provider
* @return InputStream
* @throws PGPException
* @deprecated use PBEDataDecryptorFactory method
*/
public InputStream getDataStream(
char[] passPhrase,
Provider provider)
throws PGPException
{
return getDataStream(new JcePBEDataDecryptorFactoryBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build()).setProvider(provider).build(passPhrase));
}