当前位置: 首页>>代码示例>>Java>>正文


Java PGPPrivateKey类代码示例

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


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


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