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


Java PGPPublicKey.RSA_ENCRYPT属性代码示例

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


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

示例1: PublicKeyKeyEncryptionMethodGenerator

protected PublicKeyKeyEncryptionMethodGenerator(
    PGPPublicKey pubKey)
{
    this.pubKey = pubKey;

    switch (pubKey.getAlgorithm())
    {
    case PGPPublicKey.RSA_ENCRYPT:
    case PGPPublicKey.RSA_GENERAL:
        break;
    case PGPPublicKey.RSA_SIGN:
        throw new IllegalArgumentException("Can't use an RSA_SIGN key for encryption.");
    case PGPPublicKey.ELGAMAL_ENCRYPT:
    case PGPPublicKey.ELGAMAL_GENERAL:
        break;
    case PGPPublicKey.ECDH:
        break;
    case PGPPublicKey.DSA:
        throw new IllegalArgumentException("Can't use DSA for encryption.");
    case PGPPublicKey.ECDSA:
        throw new IllegalArgumentException("Can't use ECDSA for encryption.");
    default:
        throw new IllegalArgumentException("unknown asymmetric algorithm: " + pubKey.getAlgorithm());
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:25,代码来源:PublicKeyKeyEncryptionMethodGenerator.java

示例2: processSessionInfo

public byte[][] processSessionInfo(
    byte[] encryptedSessionInfo)
    throws PGPException
{
    byte[][] data;

    switch (pubKey.getAlgorithm())
    {
    case PGPPublicKey.RSA_ENCRYPT:
    case PGPPublicKey.RSA_GENERAL:
        data = new byte[1][];

        data[0] = convertToEncodedMPI(encryptedSessionInfo);
        break;
    case PGPPublicKey.ELGAMAL_ENCRYPT:
    case PGPPublicKey.ELGAMAL_GENERAL:
        byte[] b1 = new byte[encryptedSessionInfo.length / 2];
        byte[] b2 = new byte[encryptedSessionInfo.length / 2];

        System.arraycopy(encryptedSessionInfo, 0, b1, 0, b1.length);
        System.arraycopy(encryptedSessionInfo, b1.length, b2, 0, b2.length);

        data = new byte[2][];
        data[0] = convertToEncodedMPI(b1);
        data[1] = convertToEncodedMPI(b2);
        break;
    case PGPPublicKey.ECDH:
        data = new byte[1][];

        data[0] = encryptedSessionInfo;
        break;
    default:
        throw new PGPException("unknown asymmetric algorithm: " + pubKey.getAlgorithm());
    }

    return data;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:37,代码来源:PublicKeyKeyEncryptionMethodGenerator.java

示例3: generateKeyRingGenerator

public final static PGPKeyRingGenerator generateKeyRingGenerator(String id, char[] pass, int s2kcount,
		KeyGenPane.BackgroundTask bgt) throws Exception
{
	// This object generates individual key-pairs.
	RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();

	// Boilerplate RSA parameters, no need to change anything
	// except for the RSA key-size (2048). You can use whatever key-size
	// makes sense for you -- 4096, etc.
	kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 2048, 12));
	bgt.setProgressPub(10);
	// First create the master (signing) key with the generator.
	PGPKeyPair rsakp_sign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, kpg.generateKeyPair(), new Date());
	// Then an encryption subkey.
	PGPKeyPair rsakp_enc = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, kpg.generateKeyPair(), new Date());
	bgt.setProgressPub(50);
	// Add a self-signature on the id
	PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
	bgt.setProgressPub(55);
	// Add signed metadata on the signature.
	// 1) Declare its purpose
	signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER);
	bgt.setProgressPub(60);
	// 2) Set preferences for secondary crypto algorithms to use when
	// sending messages to this key.
	signhashgen.setPreferredSymmetricAlgorithms(false, new int[] { SymmetricKeyAlgorithmTags.AES_256,
			SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_128 });
	signhashgen.setPreferredHashAlgorithms(false, new int[] { HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1,
			HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224, });
	// 3) Request senders add additional checksums to the message (useful
	// when verifying unsigned messages.)
	signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);

	// Create a signature on the encryption subkey.
	PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
	// Add metadata to declare its purpose
	enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

	// Objects used to encrypt the secret key.
	PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
	PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
	bgt.setProgressPub(70);
	// bcpg 1.48 exposes this API that includes s2kcount. Earlier versions
	// use a default of 0x60.
	PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc,
			s2kcount)).build(pass);

	// Finally, create the keyring itself. The constructor takes parameters
	// that allow it to generate the self signature.
	PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsakp_sign, id,
			sha1Calc, signhashgen.generate(), null,
			new BcPGPContentSignerBuilder(rsakp_sign.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), pske);
	bgt.setProgressPub(80);
	// Add our encryption subkey, together with its signature.
	keyRingGen.addSubKey(rsakp_enc, enchashgen.generate(), null);
	bgt.setProgressPub(90);
	return keyRingGen;
}
 
开发者ID:AnonymOnline,项目名称:saveOrganizer,代码行数:58,代码来源:RSAGen.java

示例4: generateKeyRingGenerator

static PGPKeyRingGenerator generateKeyRingGenerator(String userId, int numBits, char[] passphrase) throws Exception  {
  RSAKeyPairGenerator keyPairGenerator = new RSAKeyPairGenerator();

  keyPairGenerator.init(
    new RSAKeyGenerationParameters(
      BigInteger.valueOf(0x10001),
      new SecureRandom(),
      numBits,
      12
    )
  );

  PGPKeyPair rsaKeyPairSign = new BcPGPKeyPair(
    PGPPublicKey.RSA_SIGN,
    keyPairGenerator.generateKeyPair(),
    new Date()
  );

  PGPKeyPair rsaKeyPairEncrypt = new BcPGPKeyPair(
    PGPPublicKey.RSA_ENCRYPT,
    keyPairGenerator.generateKeyPair(),
    new Date()
  );

  PGPSignatureSubpacketGenerator signHashGenerator = new PGPSignatureSubpacketGenerator();

  signHashGenerator.setKeyFlags(false, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER);

  signHashGenerator.setPreferredSymmetricAlgorithms(
    false,
    new int[] {
      SymmetricKeyAlgorithmTags.AES_256,
      SymmetricKeyAlgorithmTags.AES_192,
      SymmetricKeyAlgorithmTags.AES_128
    }
  );

  signHashGenerator.setPreferredHashAlgorithms(
    false,
    new int[] {
      HashAlgorithmTags.SHA512,
      HashAlgorithmTags.SHA384,
      HashAlgorithmTags.SHA256,
      HashAlgorithmTags.SHA1,    // Not recommended
      HashAlgorithmTags.SHA224,  // Not recommended
    }
  );

  signHashGenerator.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);

  PGPSignatureSubpacketGenerator encryptHashGenerator = new PGPSignatureSubpacketGenerator();

  encryptHashGenerator.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

  PGPDigestCalculator sha1DigestCalculator = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
  PGPDigestCalculator sha512DigestCalculator = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA512);

  PBESecretKeyEncryptor secretKeyEncryptor = (
    new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha512DigestCalculator)
  )
    .build(passphrase);

  PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(
    PGPSignature.NO_CERTIFICATION,
    rsaKeyPairSign,
    userId,
    sha1DigestCalculator,
    signHashGenerator.generate(),
    null,
    new BcPGPContentSignerBuilder(rsaKeyPairSign.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA512),
    secretKeyEncryptor
  );

  keyRingGen.addSubKey(rsaKeyPairEncrypt, encryptHashGenerator.generate(), null);

  return keyRingGen;
}
 
开发者ID:quan-to,项目名称:react-native-pgp,代码行数:77,代码来源:PGPUtils.java


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