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

Java PGPPrivateKey类代码示例

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

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



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

示例1: findSecretKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的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: writeKeyPairToParcel

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
private static void writeKeyPairToParcel(PGPKeyPair keypair, Parcel dest) throws IOException {
    // write private key
    PGPPrivateKey priv = keypair.getPrivateKey();
    // key ID
    dest.writeLong(priv.getKeyID());
    // private key data packet
    byte[] privData = priv.getPrivateKeyDataPacket().getEncoded();
    dest.writeInt(privData.length);
    dest.writeByteArray(privData);
    // public key packet
    byte[] privPubKey = priv.getPublicKeyPacket().getEncoded();
    dest.writeInt(privPubKey.length);
    dest.writeByteArray(privPubKey);

    // write public key
    PGPPublicKey pub = keypair.getPublicKey();
    // whole public key
    byte[] pubPacket = pub.getEncoded();
    dest.writeInt(pubPacket.length);
    dest.writeByteArray(pubPacket);
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:22,代码来源:PGP.java


示例3: fromParcel

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
public static PGPDecryptedKeyPairRing fromParcel(Parcel in) throws PGPException {
    ensureKeyConverter();

    // TODO read byte data
    PrivateKey privSign = (PrivateKey) in.readSerializable();
    PublicKey pubSign = (PublicKey) in.readSerializable();
    int algoSign = in.readInt();
    Date dateSign = new Date(in.readLong());

    PGPPublicKey pubKeySign = sKeyConverter.getPGPPublicKey(algoSign, pubSign, dateSign);
    PGPPrivateKey privKeySign = sKeyConverter.getPGPPrivateKey(pubKeySign, privSign);
    PGPKeyPair signKp = new PGPKeyPair(pubKeySign, privKeySign);

    PrivateKey privEnc = (PrivateKey) in.readSerializable();
    PublicKey pubEnc = (PublicKey) in.readSerializable();
    int algoEnc = in.readInt();
    Date dateEnc = new Date(in.readLong());

    PGPPublicKey pubKeyEnc = sKeyConverter.getPGPPublicKey(algoEnc, pubEnc, dateEnc);
    PGPPrivateKey privKeyEnc = sKeyConverter.getPGPPrivateKey(pubKeyEnc, privEnc);
    PGPKeyPair encryptKp = new PGPKeyPair(pubKeyEnc, privKeyEnc);

    return new PGPDecryptedKeyPairRing(signKp, encryptKp);
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:25,代码来源:PGP.java


示例4: findSecretKey

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


示例5: extractPrivateKey

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


示例6: revokeKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
/** Revokes the given key. */
public static PGPPublicKey revokeKey(PGPKeyPair secret)
        throws PGPException, IOException, SignatureException {

    PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
    PGPPublicKey pgpPubKey = secret.getPublicKey();

    PGPSignatureGenerator       sGen = new PGPSignatureGenerator(
        new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
            PGPUtil.SHA256).setProvider(PROVIDER));

    sGen.init(PGPSignature.KEY_REVOCATION, pgpPrivKey);

    return PGPPublicKey.addCertification(pgpPubKey, sGen.generateCertification(pgpPubKey));
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:16,代码来源:PGP.java


示例7: unserialize

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
public static PGPDecryptedKeyPairRing unserialize(ObjectInputStream in)
        throws IOException, ClassNotFoundException, PGPException {
    ensureKeyConverter();

    // TODO read byte data

    PrivateKey privAuth = (PrivateKey) in.readObject();
    PublicKey pubAuth = (PublicKey) in.readObject();
    int algoAuth = in.readInt();
    Date dateAuth = new Date(in.readLong());

    PGPPublicKey pubKeyAuth = sKeyConverter.getPGPPublicKey(algoAuth, pubAuth, dateAuth);
    PGPPrivateKey privKeyAuth = sKeyConverter.getPGPPrivateKey(pubKeyAuth, privAuth);
    PGPKeyPair authKp = new PGPKeyPair(pubKeyAuth, privKeyAuth);

    PrivateKey privSign = (PrivateKey) in.readObject();
    PublicKey pubSign = (PublicKey) in.readObject();
    int algoSign = in.readInt();
    Date dateSign = new Date(in.readLong());

    PGPPublicKey pubKeySign = sKeyConverter.getPGPPublicKey(algoSign, pubSign, dateSign);
    PGPPrivateKey privKeySign = sKeyConverter.getPGPPrivateKey(pubKeySign, privSign);
    PGPKeyPair signKp = new PGPKeyPair(pubKeySign, privKeySign);

    PrivateKey privEnc = (PrivateKey) in.readObject();
    PublicKey pubEnc = (PublicKey) in.readObject();
    int algoEnc = in.readInt();
    Date dateEnc = new Date(in.readLong());

    PGPPublicKey pubKeyEnc = sKeyConverter.getPGPPublicKey(algoEnc, pubEnc, dateEnc);
    PGPPrivateKey privKeyEnc = sKeyConverter.getPGPPrivateKey(pubKeyEnc, privEnc);
    PGPKeyPair encryptKp = new PGPKeyPair(pubKeyEnc, privKeyEnc);

    return new PGPDecryptedKeyPairRing(authKp, signKp, encryptKp);
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:36,代码来源:PGP.java


示例8: createCertificate

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
public static X509Certificate createCertificate(PGPPublicKeyRing publicKeyring, PGPSecretKey secretKey, String passphrase)
    throws PGPException, InvalidKeyException, IllegalStateException,
    NoSuchAlgorithmException, SignatureException, CertificateException,
    NoSuchProviderException, IOException, OperatorCreationException {

    // extract the private key
    PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
    PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
        .setProvider(PGP.PROVIDER)
        .build(passphrase.toCharArray());

    PGPPrivateKey privateKey = secretKey.extractPrivateKey(decryptor);
    return createCertificate(publicKeyring, privateKey);

}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:16,代码来源:X509Bridge.java


示例9: signPublicKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
/** Signs a public key with the given secret key. */
public static PGPPublicKey signPublicKey(PGPKeyPair secret, PGPPublicKey keyToBeSigned, String id, int certification)
        throws PGPException, IOException, SignatureException {

    PGPPrivateKey pgpPrivKey = secret.getPrivateKey();

    PGPSignatureGenerator       sGen = new PGPSignatureGenerator(
        new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
            PGPUtil.SHA1).setProvider(PROVIDER));

    sGen.init(certification, pgpPrivKey);

    return PGPPublicKey.addCertification(keyToBeSigned, id, sGen.generateCertification(id, keyToBeSigned));
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:15,代码来源:PGP.java


示例10: signUserAttributes

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
/** Signs and add the given user attributes to the given public key. */
public static PGPPublicKey signUserAttributes(PGPKeyPair secret, PGPPublicKey keyToBeSigned, PGPUserAttributeSubpacketVector attributes, int certification)
        throws PGPException, SignatureException {

    PGPPrivateKey pgpPrivKey = secret.getPrivateKey();

    PGPSignatureGenerator       sGen = new PGPSignatureGenerator(
        new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
            PGPUtil.SHA1).setProvider(PROVIDER));

    sGen.init(certification, pgpPrivKey);

    return PGPPublicKey.addCertification(keyToBeSigned, attributes,
            sGen.generateCertification(attributes, keyToBeSigned));
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:16,代码来源:PGP.java


示例11: revokeKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
/** Revokes the given key. */
public static PGPPublicKey revokeKey(PGPKeyPair secret)
        throws PGPException, IOException, SignatureException {

    PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
    PGPPublicKey pgpPubKey = secret.getPublicKey();

    PGPSignatureGenerator       sGen = new PGPSignatureGenerator(
        new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
            PGPUtil.SHA1).setProvider(PROVIDER));

    sGen.init(PGPSignature.KEY_REVOCATION, pgpPrivKey);

    return PGPPublicKey.addCertification(pgpPubKey, sGen.generateCertification(pgpPubKey));
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:16,代码来源:PGP.java


示例12: createCertificate

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
public static X509Certificate createCertificate(PGPPublicKeyRing publicKeyring, PGPSecretKey secretKey, String passphrase, String subjectAltName)
        throws PGPException, InvalidKeyException, IllegalStateException,
        NoSuchAlgorithmException, SignatureException, CertificateException,
        NoSuchProviderException, IOException {

    // extract the private key
    PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
    PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
        .setProvider(PGP.PROVIDER)
        .build(passphrase.toCharArray());

    PGPPrivateKey privateKey = secretKey.extractPrivateKey(decryptor);
    return createCertificate(publicKeyring, privateKey, subjectAltName);

}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:16,代码来源:X509Bridge.java


示例13: findSecretKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的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
 * @throws PGPException
 * @throws NoSuchProviderException
 */
public 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(pass, "SC");
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:24,代码来源:EncryptionUtils.java


示例14: getPrivateKey

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


示例15: readKeyPairFromParcel

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
private static PGPKeyPair readKeyPairFromParcel(Parcel in) throws IOException, PGPException {
    BCPGInputStream reader = null;
    long privID;
    BCPGKey privData;
    PublicKeyPacket privPubKey;

    // rebuild private key

    try {
        // key ID
        privID = in.readLong();

        // private key data packet
        int privDataLength = in.readInt();
        byte[] privDataData = new byte[privDataLength];
        in.readByteArray(privDataData);
        // object will be read later

        // public key packet
        int privPubKeyLength = in.readInt();
        byte[] privPubKeyData = new byte[privPubKeyLength];
        in.readByteArray(privPubKeyData);

        reader = new BCPGInputStream(new ByteArrayInputStream(privPubKeyData));
        privPubKey = (PublicKeyPacket) reader.readPacket();
        reader.close();

        reader = new BCPGInputStream(new ByteArrayInputStream(privDataData));

        // from PGPSecretKey
        // apparently there is no way to make this dynamic
        switch (privPubKey.getAlgorithm())
        {
            case PGPPublicKey.RSA_ENCRYPT:
            case PGPPublicKey.RSA_GENERAL:
            case PGPPublicKey.RSA_SIGN:
                privData = new RSASecretBCPGKey(reader);
                break;
            case PGPPublicKey.DSA:
                privData = new DSASecretBCPGKey(reader);
                break;
            case PGPPublicKey.ELGAMAL_ENCRYPT:
            case PGPPublicKey.ELGAMAL_GENERAL:
                privData = new ElGamalSecretBCPGKey(reader);
                break;
            case PGPPublicKey.ECDH:
            case PGPPublicKey.ECDSA:
                privData = new ECSecretBCPGKey(reader);
                break;
            default:
                throw new PGPException("unknown public key algorithm encountered");
        }

        reader.close();
    }
    finally {
        try {
            if (reader != null)
                reader.close();
        }
        catch (IOException ignored) {
        }
    }

    PGPPrivateKey priv = new PGPPrivateKey(privID, privPubKey, privData);

    // rebuild public key
    // public key data
    int pubKeyLength = in.readInt();
    byte[] pubKeyData = new byte[pubKeyLength];
    in.readByteArray(pubKeyData);

    PGPObjectFactory f = new PGPObjectFactory(pubKeyData, sFingerprintCalculator);
    PGPPublicKeyRing pubring = (PGPPublicKeyRing) f.nextObject();
    PGPPublicKey pub = pubring.getPublicKey();

    return new PGPKeyPair(pub, priv);
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:79,代码来源:PGP.java


示例16: convertPrivateKey

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
public static PrivateKey convertPrivateKey(PGPPrivateKey key) throws PGPException {
    ensureKeyConverter();
    return sKeyConverter.getPrivateKey(key);
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:5,代码来源:PGP.java


示例17: sign

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


示例18: applySignature

import org.spongycastle.openpgp.PGPPrivateKey; //导入依赖的package包/类
@SuppressWarnings({ "deprecation" })
public static byte[] applySignature(byte[] data, PGPSecretKey secretKey, PGPPublicKey publicKey, PGPPrivateKey privateKey) throws NoSuchAlgorithmException, PGPException, IOException, SignatureException {
	BouncyCastleProvider bc = new BouncyCastleProvider();
	Security.addProvider(bc);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	
	OutputStream targetOut = new ArmoredOutputStream(baos);
	
	PGPSignatureGenerator sGen = new PGPSignatureGenerator(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1, bc);
	sGen.initSign(PGPSignature.BINARY_DOCUMENT, privateKey);
	
	PGPCompressedDataGenerator cGen = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZLIB);
	BCPGOutputStream bOut = new BCPGOutputStream(cGen.open(targetOut));
	
	sGen.update(data);
	
	sGen.generate().encode(bOut);
	
	cGen.close();
	bOut.close();
	targetOut.close();
	
	byte[] outdata = baos.toByteArray();
	return outdata;


}
 
开发者ID:guardianproject,项目名称:CameraV,代码行数:29,代码来源:KeyUtility.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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