本文整理汇总了Java中org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcePBESecretKeyEncryptorBuilder类的具体用法?Java JcePBESecretKeyEncryptorBuilder怎么用?Java JcePBESecretKeyEncryptorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JcePBESecretKeyEncryptorBuilder类属于org.bouncycastle.openpgp.operator.jcajce包,在下文中一共展示了JcePBESecretKeyEncryptorBuilder类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createPGPKeyRingGenerator
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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;
}
开发者ID:george-haddad,项目名称:bouncycastle,代码行数:29,代码来源:PGPKeyTools.java
示例2: PGPSecretKey
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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));
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:19,代码来源:PGPSecretKey.java
示例3: PGPKeyRingGenerator
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的package包/类
/**
* Create a new key ring generator.
*
* @param certificationLevel the certification level for keys on this ring.
* @param masterKey the master key pair.
* @param id the id to be associated with the ring.
* @param encAlgorithm the algorithm to be used to protect secret keys.
* @param passPhrase the passPhrase to be used to protect secret keys.
* @param useSHA1 checksum the secret keys with SHA1 rather than the older 16 bit checksum.
* @param hashedPcks packets to be included in the certification hash.
* @param unhashedPcks packets to be attached unhashed to the certification.
* @param rand input secured random
* @param provider the provider to use for encryption.
*
* @throws PGPException
* @throws NoSuchProviderException
* @deprecated use method taking PBESecretKeyEncryptor
*/
public PGPKeyRingGenerator(
int certificationLevel,
PGPKeyPair masterKey,
String id,
int encAlgorithm,
char[] passPhrase,
boolean useSHA1,
PGPSignatureSubpacketVector hashedPcks,
PGPSignatureSubpacketVector unhashedPcks,
SecureRandom rand,
Provider provider)
throws PGPException, NoSuchProviderException
{
this.masterKey = masterKey;
this.hashedPcks = hashedPcks;
this.unhashedPcks = unhashedPcks;
this.keyEncryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider).setSecureRandom(rand).build(passPhrase);
this.checksumCalculator = convertSHA1Flag(useSHA1);
this.keySignerBuilder = new JcaPGPContentSignerBuilder(masterKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);
keys.add(new PGPSecretKey(certificationLevel, masterKey, id, checksumCalculator, hashedPcks, unhashedPcks, keySignerBuilder, keyEncryptor));
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:41,代码来源:PGPKeyRingGenerator.java
示例4: copySecretKeyRingWithNewPassword
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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);
}
}
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:23,代码来源:PGPUtils.java
示例5: relock
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的package包/类
/**
* Re-encrypts the key set with a new passphrase and returns it in locked
* form.
*
* @param oldPassphrase the old passphrase
* @param newPassphrase the new passphrase
* @return {@code this}, re-encrypted with {@code newPassphrase}
* @throws CryptographicException if {@code oldPassphrase} is incorrect
*/
public KeySet relock(char[] oldPassphrase, char[] newPassphrase, SecureRandom random) throws CryptographicException {
try {
final PBESecretKeyDecryptor decryptor =
new JcePBESecretKeyDecryptorBuilder()
.build(oldPassphrase);
final PBESecretKeyEncryptor encryptor =
new JcePBESecretKeyEncryptorBuilder(SymmetricAlgorithm.DEFAULT.value())
.setSecureRandom(random)
.build(newPassphrase);
final PGPSecretKey masterSecretKey = PGPSecretKey.copyWithNewPassword(
getUnlockedMasterKey().getSecretKey(),
decryptor,
encryptor
);
final PGPSecretKey subSecretKey = PGPSecretKey.copyWithNewPassword(
getUnlockedSubKey().getSecretKey(),
decryptor,
encryptor
);
final MasterKey newMasterKey = new MasterKey(masterSecretKey);
final SubKey newSubKey = new SubKey(subSecretKey, newMasterKey);
return new KeySet(newMasterKey, newSubKey);
} catch (PGPException e) {
throw new CryptographicException(e);
}
}
开发者ID:codahale,项目名称:gpgj,代码行数:38,代码来源:UnlockedKeySet.java
示例6: generateAndSign
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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");
}
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:60,代码来源:PGPECDSATest.java
示例7: generate
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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");
}
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:61,代码来源:PGPECDHTest.java
示例8: generate
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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);
}
}
开发者ID:codahale,项目名称:gpgj,代码行数:67,代码来源:KeySetGenerator.java
示例9: copyWithNewPassword
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; //导入依赖的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));
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:24,代码来源:PGPSecretKey.java
注:本文中的org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论