本文整理汇总了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;
}
示例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()));
}
}
示例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 );
}
}