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


Java PGPPublicKeyRing.encode方法代码示例

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


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

示例1: doInBackground

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


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