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


Java PGPKeyRingGenerator.generatePublicKeyRing方法代码示例

本文整理汇总了Java中org.bouncycastle.openpgp.PGPKeyRingGenerator.generatePublicKeyRing方法的典型用法代码示例。如果您正苦于以下问题:Java PGPKeyRingGenerator.generatePublicKeyRing方法的具体用法?Java PGPKeyRingGenerator.generatePublicKeyRing怎么用?Java PGPKeyRingGenerator.generatePublicKeyRing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.openpgp.PGPKeyRingGenerator的用法示例。


在下文中一共展示了PGPKeyRingGenerator.generatePublicKeyRing方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doInBackground

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
@Override
protected Void doInBackground() throws Exception
{
	Main.logger.info("Neue Schlüssel werden generiert...");
	PGPKeyRingGenerator pkg = RSAGen.generateKeyRingGenerator(mail, pass, this);
	PGPPublicKeyRing pkr = pkg.generatePublicKeyRing();
	PGPSecretKeyRing skr = pkg.generateSecretKeyRing();
	Main.psk = skr.getSecretKey();
	Iterator<PGPPublicKey> rIt = pkr.getPublicKeys();

	// Sucht den Verschlüsselungsschlüssel
	while (Main.ppk == null && rIt.hasNext())
	{
		PGPPublicKey temp_key = rIt.next();
		if (temp_key.isEncryptionKey())
		{
			Main.ppk = temp_key;
			break;
		}
	}

	PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder()
			.setProvider(BouncyCastleProvider.PROVIDER_NAME).build(pass);
	Main.pprk = Main.psk.extractPrivateKey(secretKeyDecryptor);
	setProgress(90);
	// Speichern der Schlüssel
	PGPSecretKeyRing pskr = pkg.generateSecretKeyRing();
	ArmoredOutputStream secout = new ArmoredOutputStream(
			new BufferedOutputStream(new FileOutputStream(Main.secKey)));
	// Geheimer Schlüssel
	pskr.encode(secout);
	secout.close();

	ArmoredOutputStream pubout = new ArmoredOutputStream(
			new BufferedOutputStream(new FileOutputStream(Main.pubKey)));
	pkr.encode(pubout);
	pubout.close();
	setProgress(100);
	return null;
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:41,代码来源:KeyGenPane.java

示例2: generateKeyPair

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
@ReactMethod
public void generateKeyPair(final String userId, final int numBits, final String passphrase, Promise promise) {
  Log.d("ReactNativePGP", "generateKeyPair");
  try {
    WritableMap resultMap = Arguments.createMap();
    PGPKeyRingGenerator keyGenerator = PGPUtils.generateKeyRingGenerator(userId, numBits, passphrase.toCharArray());

    // public key
    PGPPublicKeyRing publicKeyRing              = keyGenerator.generatePublicKeyRing();
    ByteArrayOutputStream publicKeyOutputStream = new ByteArrayOutputStream();
    ArmoredOutputStream armoredPubOutputStream  = new ArmoredOutputStream(publicKeyOutputStream);

    publicKeyRing.encode(armoredPubOutputStream);
    armoredPubOutputStream.close();
    resultMap.putString("publicKey", publicKeyOutputStream.toString("UTF-8"));

    // private key
    PGPSecretKeyRing secretKeyRing               = keyGenerator.generateSecretKeyRing();
    ByteArrayOutputStream privateKeyOutputStream = new ByteArrayOutputStream();
    ArmoredOutputStream armoredPrivOutputStream  = new ArmoredOutputStream(privateKeyOutputStream);

    secretKeyRing.encode(armoredPrivOutputStream);
    armoredPrivOutputStream.close();
    resultMap.putString("privateKey", privateKeyOutputStream.toString("UTF-8"));
    resultMap.putString("fingerPrint", Utils.bytesToHex(secretKeyRing.getPublicKey().getFingerprint()));

    promise.resolve(resultMap);
  } catch(Exception e) {
    promise.reject(new Exception(e.getMessage()));
  }
}
 
开发者ID:quan-to,项目名称:react-native-pgp,代码行数:32,代码来源:Module.java

示例3: generateKeyPair

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public static KeyPair generateKeyPair( String userId, String secretPwd, boolean armored ) throws PGPException
{
    try
    {
        KeyPair keyPair = new KeyPair();

        PGPKeyRingGenerator krgen = generateKeyRingGenerator( userId, secretPwd, keyPair );

        // Generate public key ring
        PGPPublicKeyRing pkr = krgen.generatePublicKeyRing();
        ByteArrayOutputStream pubOut = new ByteArrayOutputStream();
        pkr.encode( pubOut );
        pubOut.close();

        // Generate private key
        PGPSecretKeyRing skr = krgen.generateSecretKeyRing();
        ByteArrayOutputStream secOut = new ByteArrayOutputStream();
        skr.encode( secOut );
        secOut.close();

        keyPair.setPubKeyring( armored ? armorByteArray( pubOut.toByteArray() ) : pubOut.toByteArray() );
        keyPair.setSecKeyring( armored ? armorByteArray( secOut.toByteArray() ) : secOut.toByteArray() );

        return keyPair;
    }
    catch ( Exception e )
    {
        throw new PGPException( "Error in generateKeyPair", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:31,代码来源:PGPEncryptionUtil.java

示例4: exportPublicKey

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public static final void exportPublicKey(PGPKeyRingGenerator pgpKeyRingGen, File keyFile, boolean asciiArmor) throws IOException {
        PGPPublicKeyRing pgpPubKeyRing = pgpKeyRingGen.generatePublicKeyRing();

        if (asciiArmor) {
                ArmoredOutputStream aos = new ArmoredOutputStream(new FileOutputStream(keyFile));
                pgpPubKeyRing.encode(aos);
                aos.close();
        }
        else {
                FileOutputStream fos = new FileOutputStream(keyFile);
                pgpPubKeyRing.encode(fos);
                fos.close();
        }
}
 
开发者ID:george-haddad,项目名称:bouncycastle,代码行数:15,代码来源:PGPKeyTools.java

示例5: generateTest

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair  dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair           elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", null, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java

示例6: generateSha1Test

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateSha1Test()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    DSAParametersGenerator  dsaPGen = new DSAParametersGenerator();

    dsaPGen.init(512, 10, new SecureRandom());

    DSAKeyPairGenerator    dsaKpg = new DSAKeyPairGenerator();

    dsaKpg.init(new DSAKeyGenerationParameters(new SecureRandom(), dsaPGen.generateParameters()));

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    AsymmetricCipherKeyPair dsaKp = dsaKpg.generateKeyPair();

    ElGamalKeyPairGenerator    elgKpg = new ElGamalKeyPairGenerator();
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameters         elParams = new ElGamalParameters(p, g);
    
    elgKpg.init(new ElGamalKeyGenerationParameters(new SecureRandom(), elParams));

    //
    // this is quicker because we are using pregenerated parameters.
    //
    AsymmetricCipherKeyPair                   elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new BcPGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new BcPGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());
    PGPDigestCalculator chkSumCalc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", chkSumCalc, null, null, new BcPGPContentSignerBuilder(PGPPublicKey.DSA, HashAlgorithmTags.SHA1), new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256).build(passPhrase));
    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:BcPGPKeyRingTest.java

示例7: generateAndSign

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的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

示例8: generateTest

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    KeyPairGenerator    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");

    dsaKpg.initialize(512);

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    KeyPair                    dsaKp = dsaKpg.generateKeyPair();

    KeyPairGenerator    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameterSpec         elParams = new ElGamalParameterSpec(p, g);
    
    elgKpg.initialize(elParams);

    //
    // this is quicker because we are using pregenerated parameters.
    //
    KeyPair                    elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:75,代码来源:BcPGPKeyRingTest.java

示例9: generateSha1Test

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateSha1Test()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    KeyPairGenerator    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");

    dsaKpg.initialize(512);

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    KeyPair                    dsaKp = dsaKpg.generateKeyPair();

    KeyPairGenerator    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameterSpec         elParams = new ElGamalParameterSpec(p, g);
    
    elgKpg.initialize(elParams);

    //
    // this is quicker because we are using pregenerated parameters.
    //
    KeyPair                    elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", PGPEncryptedData.AES_256, passPhrase, true, null, null, new SecureRandom(), "BC");

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:75,代码来源:BcPGPKeyRingTest.java

示例10: generateTest

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    KeyPairGenerator    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");

    dsaKpg.initialize(512);

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    KeyPair                    dsaKp = dsaKpg.generateKeyPair();

    KeyPairGenerator    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameterSpec         elParams = new ElGamalParameterSpec(p, g);
    
    elgKpg.initialize(elParams);

    //
    // this is quicker because we are using pregenerated parameters.
    //
    KeyPair                    elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.initVerify(vKey, "BC");

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:75,代码来源:PGPKeyRingTest.java

示例11: generate

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的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

示例12: generateTest

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateTest()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    KeyPairGenerator    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");

    dsaKpg.initialize(512);

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    KeyPair                    dsaKp = dsaKpg.generateKeyPair();

    KeyPairGenerator    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameterSpec         elParams = new ElGamalParameterSpec(p, g);
    
    elgKpg.initialize(512);

    //
    // this is quicker because we are using pregenerated parameters.
    //
    KeyPair                    elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", PGPEncryptedData.AES_256, passPhrase, null, null, new SecureRandom(), "BC");

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:75,代码来源:BcPGPKeyRingTest.java

示例13: generateSha1Test

import org.bouncycastle.openpgp.PGPKeyRingGenerator; //导入方法依赖的package包/类
public void generateSha1Test()
    throws Exception
{
    char[]              passPhrase = "hello".toCharArray();
    KeyPairGenerator    dsaKpg = KeyPairGenerator.getInstance("DSA", "BC");

    dsaKpg.initialize(512);

    //
    // this takes a while as the key generator has to generate some DSA params
    // before it generates the key.
    //
    KeyPair                    dsaKp = dsaKpg.generateKeyPair();

    KeyPairGenerator    elgKpg = KeyPairGenerator.getInstance("ELGAMAL", "BC");
    BigInteger             g = new BigInteger("153d5d6172adb43045b68ae8e1de1070b6137005686d29d3d73a7749199681ee5b212c9b96bfdcfa5b20cd5e3fd2044895d609cf9b410b7a0f12ca1cb9a428cc", 16);
    BigInteger             p = new BigInteger("9494fec095f3b85ee286542b3836fc81a5dd0a0349b4c239dd38744d488cf8e31db8bcb7d33b41abb9e5a33cca9144b1cef332c94bf0573bf047a3aca98cdf3b", 16);
    
    ElGamalParameterSpec         elParams = new ElGamalParameterSpec(p, g);
    
    elgKpg.initialize(512);

    //
    // this is quicker because we are using pregenerated parameters.
    //
    KeyPair                    elgKp = elgKpg.generateKeyPair();
    PGPKeyPair        dsaKeyPair = new PGPKeyPair(PGPPublicKey.DSA, dsaKp, new Date());
    PGPKeyPair        elgKeyPair = new PGPKeyPair(PGPPublicKey.ELGAMAL_ENCRYPT, elgKp, new Date());

    PGPKeyRingGenerator    keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, dsaKeyPair,
            "test", PGPEncryptedData.AES_256, passPhrase, true, null, null, new SecureRandom(), "BC");

    keyRingGen.addSubKey(elgKeyPair);

    PGPSecretKeyRing       keyRing = keyRingGen.generateSecretKeyRing();
    
    keyRing.getSecretKey().extractPrivateKey(new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(passPhrase));
    
    PGPPublicKeyRing        pubRing = keyRingGen.generatePublicKeyRing();
    
    PGPPublicKey            vKey = null;
    PGPPublicKey            sKey = null;
    
    Iterator                    it = pubRing.getPublicKeys();
    while (it.hasNext())
    {
        PGPPublicKey    pk = (PGPPublicKey)it.next();
        if (pk.isMasterKey())
        {
            vKey = pk;
        }
        else
        {
            sKey = pk;
        }
    }
    
    Iterator    sIt = sKey.getSignatures();
    while (sIt.hasNext())
    {
        PGPSignature    sig = (PGPSignature)sIt.next();
        
        if (sig.getKeyID() == vKey.getKeyID()
            && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING)
        {
            sig.init(new BcPGPContentVerifierBuilderProvider(), vKey);

            if (!sig.verifyCertification(vKey, sKey))
            {
                fail("failed to verify sub-key signature.");
            }
        }
    }
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:75,代码来源:BcPGPKeyRingTest.java


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