• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JcePBESecretKeyDecryptorBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder的典型用法代码示例。如果您正苦于以下问题:Java JcePBESecretKeyDecryptorBuilder类的具体用法?Java JcePBESecretKeyDecryptorBuilder怎么用?Java JcePBESecretKeyDecryptorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JcePBESecretKeyDecryptorBuilder类属于org.spongycastle.openpgp.operator.jcajce包,在下文中一共展示了JcePBESecretKeyDecryptorBuilder类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findSecretKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static PGPPrivateKey findSecretKey(PGPSecretKeyRingCollection pgpSec, long keyID, char[] pass)
        throws PGPException, NoSuchProviderException
{
    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);
    PGPPrivateKey x;
    if (pgpSecKey == null)
    {
        return null;
    }

    try{
        Log.d("decrypt", "findSecretKey: fixing something");
       x =pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(pass));
    }catch (Exception ex){
        ex.printStackTrace();
        return null;
    }
    return x;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:20,代码来源:KeyManagement.java


示例2: convertPrivateKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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


示例3: createCertificate

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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


示例4: convertPrivateKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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: findSecretKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
/**
 * Load a secret key ring collection from keyIn and find the secret key corresponding to
 * keyID if it exists.
 *
 * @param keyIn input stream representing a key ring collection.
 * @param keyID keyID we want.
 * @param pass  passphrase to decrypt secret key with.
 * @return
 * @throws IOException
 * @throws PGPException
 * @throws NoSuchProviderException
 */
public PGPPrivateKey findSecretKey(InputStream keyIn, long keyID, char[] pass)
        throws IOException, PGPException, NoSuchProviderException {
    PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
            PGPUtil.getDecoderStream(keyIn));

    PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

    if (pgpSecKey == null) {
        return null;
    }

    PBESecretKeyDecryptor a = new JcePBESecretKeyDecryptorBuilder(new JcaPGPDigestCalculatorProviderBuilder().setProvider("BC").build()).setProvider("BC").build(pass);

    return pgpSecKey.extractPrivateKey(a);
}
 
开发者ID:guardianproject,项目名称:CameraV,代码行数:28,代码来源:PgpHelper.java


示例7: findSecretKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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));
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:24,代码来源:MyPGPUtil.java


示例8: extractPrivateKey

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
/**
 * Function to turn the private key into one that can be used for decrypting.
 *
 * @param passphrase Passphrase that unlocks the private key.
 */
public static PGPPrivateKey extractPrivateKey(byte[] privateKey, String passphrase) {
    PGPSecretKey secretKey = getSecretKey(privateKey);
    try {
        PBESecretKeyDecryptor decrypterFactory = new JcePBESecretKeyDecryptorBuilder()
                .setProvider(SECURITY_PROVIDER)
                .build(passphrase.toCharArray());
        return secretKey.extractPrivateKey(decrypterFactory);
    } catch (PGPException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:cpoppema,项目名称:pass-mobile-android,代码行数:19,代码来源:PgpHelper.java


示例9: changePassphrase

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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: copySecretKeyRingWithNewPassword

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
public static PGPSecretKeyRing copySecretKeyRingWithNewPassword(PGPSecretKeyRing secRing,
        String oldPassphrase, String newPassphrase) throws PGPException {

    PGPDigestCalculatorProvider digestCalcProv = new JcaPGPDigestCalculatorProviderBuilder().build();
    PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(digestCalcProv)
        .setProvider(PGP.PROVIDER)
        .build(oldPassphrase.toCharArray());

    PGPDigestCalculator digestCalc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA256);
    PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, digestCalc)
        .setProvider(PROVIDER).build(newPassphrase.toCharArray());

    return PGPSecretKeyRing.copyWithNewPassword(secRing, decryptor, encryptor);
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:15,代码来源:PGP.java


示例11: changePassphrase

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的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


示例12: sign

import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static String sign(String stanza, String keyPath, char[] pass) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, PGPException, SignatureException {
	if (stanza == null) {
		stanza = "";
	}

	PGPSecretKey pgpSecKey = EncryptionUtils.readSecretKey(keyPath);
	PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("SC").build(pass));
	PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSecKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("SC"));
	PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();

	sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);

	Iterator it = pgpSecKey.getPublicKey().getUserIDs();
	if (it.hasNext()) {
		spGen.setSignerUserID(false, (String) it.next());
		sGen.setHashedSubpackets(spGen.generate());
	}

	InputStream fIn = new BufferedInputStream(new ByteArrayInputStream(stanza.getBytes()));
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ArmoredOutputStream aOut = new ArmoredOutputStream(out);

	aOut.beginClearText(PGPUtil.SHA1);

	//
	// note the last \n/\r/\r\n in the file is ignored
	//
	ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
	int lookAhead = readInputLine(lineOut, fIn);

	processLine(aOut, sGen, lineOut.toByteArray());

	if (lookAhead != -1) {
		do {
			lookAhead = readInputLine(lineOut, lookAhead, fIn);

			sGen.update((byte) '\r');
			sGen.update((byte) '\n');

			processLine(aOut, sGen, lineOut.toByteArray());
		} while (lookAhead != -1);
	}

	fIn.close();

	aOut.endClearText();

	BCPGOutputStream bOut = new BCPGOutputStream(aOut);

	sGen.generate().encode(bOut);

	aOut.close();

	String signed = new String(out.toByteArray());

	bOut.close();

	return EncryptedDataProvider.removeHeaderFooter(signed);

}
 
开发者ID:snuk182,项目名称:aceim,代码行数:62,代码来源:SignedPresence.java



注:本文中的org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CtReturn类代码示例发布时间:2022-05-22
下一篇:
Java Message类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap