本文整理汇总了Java中org.spongycastle.openpgp.PGPSecretKeyRing类的典型用法代码示例。如果您正苦于以下问题:Java PGPSecretKeyRing类的具体用法?Java PGPSecretKeyRing怎么用?Java PGPSecretKeyRing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPSecretKeyRing类属于org.spongycastle.openpgp包,在下文中一共展示了PGPSecretKeyRing类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convertPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static PrivateKey convertPrivateKey(byte[] privateKeyData, String passphrase)
throws PGPException, IOException {
PGPDigestCalculatorProvider digestCalc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(digestCalc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// load the secret key ring
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
// search and decrypt the master (signing key)
// secret keys
Iterator<PGPSecretKey> skeys = secRing.getSecretKeys();
while (skeys.hasNext()) {
PGPSecretKey key = skeys.next();
PGPSecretKey sec = secRing.getSecretKey();
if (key.isMasterKey())
return convertPrivateKey(sec.extractPrivateKey(decryptor));
}
throw new PGPException("no suitable private key found.");
}
开发者ID:kontalk,项目名称:androidclient,代码行数:26,代码来源:PGP.java
示例2: createCertificate
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException, OperatorCreationException {
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, sFingerprintCalculator);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor));
}
开发者ID:kontalk,项目名称:androidclient,代码行数:18,代码来源:X509Bridge.java
示例3: store
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/** Creates public and secret keyring for a given keypair. */
public static PGPKeyPairRing store(PGPDecryptedKeyPairRing pair,
String id,
String passphrase)
throws PGPException {
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pair.signKey,
id, sha1Calc, null, null,
new JcaPGPContentSignerBuilder(pair.signKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc)
.setProvider(PROVIDER).build(passphrase.toCharArray()));
keyRingGen.addSubKey(pair.encryptKey);
PGPSecretKeyRing secRing = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
return new PGPKeyPairRing(pubRing, secRing);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:21,代码来源:PGP.java
示例4: convertPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static PrivateKey convertPrivateKey(byte[] privateKeyData, String passphrase)
throws PGPException, IOException {
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// load the secret key ring
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
// search and decrypt the master (signing key)
// secret keys
Iterator<PGPSecretKey> skeys = secRing.getSecretKeys();
while (skeys.hasNext()) {
PGPSecretKey key = skeys.next();
PGPSecretKey sec = secRing.getSecretKey();
if (key.isMasterKey())
return convertPrivateKey(sec.extractPrivateKey(decryptor));
}
throw new PGPException("no suitable private key found.");
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:27,代码来源:PGP.java
示例5: createCertificate
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase, String subjectAltName)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor), subjectAltName);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:19,代码来源:X509Bridge.java
示例6: doInBackground
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
@Override
protected byte[] doInBackground(Void... strings) {
String email = SharedData.USERNAME;
char[] password = mKeyPassword.toCharArray();
try {
Log.d(TAG,"start generating keys");
PGPKeyRingGenerator keyRingGenerator = new KeyManagement().generateKey(email,password);
PGPPublicKeyRing publicKeys = keyRingGenerator.generatePublicKeyRing();
PGPSecretKeyRing secretKeys = keyRingGenerator.generateSecretKeyRing();
//output keys in ascii armored format
File file = new File(getFilesDir(),"pub.asc");
ArmoredOutputStream pubOut = new ArmoredOutputStream(new FileOutputStream(file));
publicKeys.encode(pubOut);
pubOut.close();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ArmoredOutputStream secOut = new ArmoredOutputStream(outputStream);
secretKeys.encode(secOut);
secOut.close();
DatabaseHandler db=new DatabaseHandler(OptionActivity.this,SharedData.DB_PASSWORD,true);
byte[] test=outputStream.toByteArray();
//call the db methods to store
db.insertSecKey(email,test);
SharedPreferences prefs=getSharedPreferences("done", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=prefs.edit();
editor.putBoolean("keys_gen",true);
editor.apply();
editor.commit();
Log.d(TAG,"secret key written to file");
return test;
} catch (Exception e) {
Log.d(TAG,"Error generating keys");
e.printStackTrace();
return null;
}
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:41,代码来源:OptionActivity.java
示例7: readSecretKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for signature generation.
*
* @param input stream to read the secret key ring collection from.
* @return a secret key.
* @throws IOException on a problem with using the input stream.
* @throws PGPException if there is an issue parsing the input stream.
*/
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
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.");
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:39,代码来源:MyPGPUtil.java
示例8: genPGPPrivKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public final static String genPGPPrivKey (PGPKeyRingGenerator krgen) throws IOException {
// String pgpPublicKey = PgpUtils.genPGPPublicKey(krgen);
//DetachedSignatureProcessor.createSignature(pgpSecretKey, )
ByteArrayOutputStream baosPriv = new ByteArrayOutputStream ();
PGPSecretKeyRing skr = krgen.generateSecretKeyRing();
ArmoredOutputStream armoredStreamPriv = new ArmoredOutputStream(baosPriv);
skr.encode(armoredStreamPriv);
armoredStreamPriv.close();
return new String(baosPriv.toByteArray(), Charset.defaultCharset());
}
开发者ID:guardianproject,项目名称:proofmode,代码行数:12,代码来源:PgpUtils.java
示例9: changePassphrase
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/**
* Set a new passphrase for the default account.
* Please note that this method does not invalidate the cached key or passphrase.
*/
public static void changePassphrase(Context ctx, String oldPassphrase, String newPassphrase, boolean fromUser)
throws PGPException, IOException {
// TODO let handle this to PGP or PersonalKey
AccountManager am = AccountManager.get(ctx);
Account acc = getDefaultAccount(am);
// get old secret key ring
String privKeyData = am.getUserData(acc, DATA_PRIVATEKEY);
byte[] privateKeyData = Base64.decode(privKeyData, Base64.DEFAULT);
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing oldSecRing = new PGPSecretKeyRing(privateKeyData, fpr);
// old decryptor
PGPDigestCalculatorProvider calcProv = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor oldDecryptor = new JcePBESecretKeyDecryptorBuilder(calcProv)
.setProvider(PGP.PROVIDER)
.build(oldPassphrase.toCharArray());
// new encryptor
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PBESecretKeyEncryptor newEncryptor = new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc)
.setProvider(PGP.PROVIDER).build(newPassphrase.toCharArray());
// create new secret key ring
PGPSecretKeyRing newSecRing = PGPSecretKeyRing.copyWithNewPassword(oldSecRing, oldDecryptor, newEncryptor);
// replace key data in AccountManager
byte[] newPrivateKeyData = newSecRing.getEncoded();
am.setUserData(acc, DATA_PRIVATEKEY, Base64.encodeToString(newPrivateKeyData, Base64.NO_WRAP));
am.setUserData(acc, DATA_USER_PASSPHRASE, String.valueOf(fromUser));
// replace password for account
am.setPassword(acc, newPassphrase);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:42,代码来源:Authenticator.java
示例10: loadArmored
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static PGPKeyPairRing loadArmored(byte[] privateKeyData, byte[] publicKeyData)
throws IOException, PGPException {
ArmoredInputStream inPublic = new ArmoredInputStream(new ByteArrayInputStream(publicKeyData));
PGPPublicKeyRing publicKey = new PGPPublicKeyRing(inPublic, sFingerprintCalculator);
ArmoredInputStream inPrivate = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData));
PGPSecretKeyRing secretKey = new PGPSecretKeyRing(inPrivate, sFingerprintCalculator);
return new PGPKeyPairRing(publicKey, secretKey);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:9,代码来源:PGP.java
示例11: copySecretKeyRingWithNewPassword
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static PGPSecretKeyRing copySecretKeyRingWithNewPassword(byte[] privateKeyData,
String oldPassphrase, String newPassphrase) throws PGPException, IOException {
// load the secret key ring
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
return copySecretKeyRingWithNewPassword(secRing, oldPassphrase, newPassphrase);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:9,代码来源:PGP.java
示例12: test
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/** Checks that the given personal key data is correct. */
public static PGPKeyPairRing test(InputStream privateKeyData, InputStream publicKeyData, String passphrase, InputStream bridgeCertData)
throws PGPException, IOException, CertificateException, NoSuchProviderException {
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, sFingerprintCalculator);
// X.509 bridge certificate
X509Certificate bridgeCert = (bridgeCertData != null) ?
X509Bridge.load(bridgeCertData) : null;
return test(secRing, pubRing, passphrase, bridgeCert);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:14,代码来源:PersonalKey.java
示例13: load
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/** Creates a {@link PersonalKey} from private and public key input streams. */
public static PersonalKey load(InputStream privateKeyData, InputStream publicKeyData, String passphrase, InputStream bridgeCertData)
throws PGPException, IOException, CertificateException, NoSuchProviderException {
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, sFingerprintCalculator);
// X.509 bridge certificate
X509Certificate bridgeCert = (bridgeCertData != null) ?
X509Bridge.load(bridgeCertData) : null;
return load(secRing, pubRing, passphrase, bridgeCert);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:14,代码来源:PersonalKey.java
示例14: changePassphrase
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/**
* Set a new passphrase for the default account.
* Please note that this method does not invalidate the cached key or passphrase.
*/
public static void changePassphrase(Context ctx, String oldPassphrase, String newPassphrase, boolean fromUser)
throws PGPException, IOException {
AccountManager am = AccountManager.get(ctx);
Account acc = getDefaultAccount(am);
// get old secret key ring
String privKeyData = am.getUserData(acc, DATA_PRIVATEKEY);
byte[] privateKeyData = Base64.decode(privKeyData, Base64.DEFAULT);
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing oldSecRing = new PGPSecretKeyRing(privateKeyData, fpr);
// old decryptor
PGPDigestCalculatorProvider calcProv = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor oldDecryptor = new JcePBESecretKeyDecryptorBuilder(calcProv)
.setProvider(PGP.PROVIDER)
.build(oldPassphrase.toCharArray());
// new encryptor
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PBESecretKeyEncryptor newEncryptor = new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc)
.setProvider(PGP.PROVIDER).build(newPassphrase.toCharArray());
// create new secret key ring
PGPSecretKeyRing newSecRing = PGPSecretKeyRing.copyWithNewPassword(oldSecRing, oldDecryptor, newEncryptor);
// replace key data in AccountManager
byte[] newPrivateKeyData = newSecRing.getEncoded();
am.setUserData(acc, DATA_PRIVATEKEY, Base64.encodeToString(newPrivateKeyData, Base64.NO_WRAP));
am.setUserData(acc, DATA_USER_PASSPHRASE, String.valueOf(fromUser));
// replace password for account
am.setPassword(acc, newPassphrase);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:40,代码来源:Authenticator.java
示例15: load
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
public static PGPKeyPairRing load(byte[] privateKeyData, byte[] publicKeyData)
throws IOException, PGPException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
ArmoredInputStream inPublic = new ArmoredInputStream(new ByteArrayInputStream(publicKeyData));
PGPPublicKeyRing publicKey = new PGPPublicKeyRing(inPublic, fpr);
ArmoredInputStream inPrivate = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData));
PGPSecretKeyRing secretKey = new PGPSecretKeyRing(inPrivate, fpr);
return new PGPKeyPairRing(publicKey, secretKey);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:10,代码来源:PGP.java
示例16: test
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/** Checks that the given personal key data is correct. */
public static PGPKeyPairRing test(InputStream privateKeyData, InputStream publicKeyData, String passphrase, InputStream bridgeCertData)
throws PGPException, IOException, CertificateException, NoSuchProviderException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr);
// X.509 bridge certificate
X509Certificate bridgeCert = X509Bridge.load(bridgeCertData);
return test(secRing, pubRing, passphrase, bridgeCert);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:14,代码来源:PersonalKey.java
示例17: load
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/** Creates a {@link PersonalKey} from private and public key input streams. */
public static PersonalKey load(InputStream privateKeyData, InputStream publicKeyData, String passphrase, InputStream bridgeCertData)
throws PGPException, IOException, CertificateException, NoSuchProviderException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr);
// X.509 bridge certificate
X509Certificate bridgeCert = (bridgeCertData != null) ?
X509Bridge.load(bridgeCertData) : null;
return load(secRing, pubRing, passphrase, bridgeCert);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:15,代码来源:PersonalKey.java
示例18: readSecretKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for signature generation.
*
* @param input stream to read the secret key ring collection from.
* @return a secret key.
* @throws IOException on a problem with using the input stream.
* @throws PGPException if there is an issue parsing the input stream.
*/
@SuppressWarnings("rawtypes")
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(input));
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
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.");
}
开发者ID:snuk182,项目名称:aceim,代码行数:40,代码来源:EncryptionUtils.java
示例19: getPrivateKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private static PGPPrivateKey getPrivateKey(PGPSecretKeyRing keyRing, long keyID, char[] pass) throws PGPException {
PGPSecretKey secretKey = keyRing.getSecretKey(keyID);
PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(pass);
return secretKey.extractPrivateKey(decryptor);
}
开发者ID:guardianproject,项目名称:proofmode,代码行数:6,代码来源:PgpUtils.java
示例20: getSecretKey
import org.spongycastle.openpgp.PGPSecretKeyRing; //导入依赖的package包/类
private static PGPSecretKey getSecretKey(byte[] privateKey) {
PGPSecretKeyRingCollection keyRing = extractSecretKeyCollection(privateKey);
Iterator<PGPSecretKeyRing> keyRingIterator = keyRing.getKeyRings();
PGPSecretKey secretKey = keyRingIterator.next().getSecretKey();
return secretKey;
}
开发者ID:cpoppema,项目名称:pass-mobile-android,代码行数:7,代码来源:PgpHelper.java
注:本文中的org.spongycastle.openpgp.PGPSecretKeyRing类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论