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


Java KeyFlags类代码示例

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


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

示例1: isEncryptionKey

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private static boolean isEncryptionKey(PGPPublicKey key) {
    if (!key.isEncryptionKey()) {
        return false;
    }
    //check keyflags
    Boolean hasEncryptionKeyFlags = hasOneOfExpectedKeyFlags(key, new int[] {KeyFlags.ENCRYPT_COMMS, KeyFlags.ENCRYPT_STORAGE });
    if (hasEncryptionKeyFlags != null && !hasEncryptionKeyFlags) {
        LOG.debug(
                "Public key with key key ID {} found for specified user ID. But this key will not be used for the encryption, because its key flags are not encryption key flags.",
                Long.toString(key.getKeyID()));
        return false;
    } else {
        // also without keyflags (hasEncryptionKeyFlags = null), true is returned!
        return true;
    }

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PGPDataFormatUtil.java

示例2: isSigningKey

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private static boolean isSigningKey(PGPSecretKey secKey) {
    if (!secKey.isSigningKey()) {
        return false;
    }
    Boolean hasSigningKeyFlag = hasOneOfExpectedKeyFlags(secKey.getPublicKey(), new int[] {KeyFlags.SIGN_DATA });
    if (hasSigningKeyFlag != null && !hasSigningKeyFlag) {
        // not a signing key --> ignore
        LOG.debug(
                "Secret key with key ID {} found for specified user ID part. But this key will not be used for signing because of its key flags.",
                Long.toString(secKey.getKeyID()));
        return false;
    } else {
        // also if there are not any keyflags (hasSigningKeyFlag=null),  true is returned!
        return true;
    }

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:PGPDataFormatUtil.java

示例3: testKeyFlagsValues

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private void testKeyFlagsValues()
{
    checkValue(KeyFlags.CERTIFY_OTHER, 0x01);
    checkValue(KeyFlags.SIGN_DATA, 0x02);
    checkValue(KeyFlags.ENCRYPT_COMMS, 0x04);
    checkValue(KeyFlags.ENCRYPT_STORAGE, 0x08);
    checkValue(KeyFlags.SPLIT, 0x10);
    checkValue(KeyFlags.AUTHENTICATION, 0x20);
    checkValue(KeyFlags.SHARED, 0x80);

    // yes this actually happens
    checkValue(new byte[] { 4, 0, 0, 0 }, 0x04);
    checkValue(new byte[] { 4, 0, 0 }, 0x04);
    checkValue(new byte[] { 4, 0 }, 0x04);
    checkValue(new byte[] { 4 }, 0x04);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:17,代码来源:PGPSignatureTest.java

示例4: getKeyFlags

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
public int getKeyFlags()
{
    SignatureSubpacket    p = this.getSubpacket(SignatureSubpacketTags.KEY_FLAGS);
    
    if (p == null)
    {
        return 0;
    }
                
    return ((KeyFlags)p).getFlags();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:12,代码来源:PGPSignatureSubpacketVector.java

示例5: isForEncryption

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
/**
 * Can public key be used for encryption
 * @param key - Public key
 * @return true if public key has required type of subkeys for encryption else false
 */
private boolean isForEncryption(PGPPublicKey key){
    if (key.getAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN
        || key.getAlgorithm() == PublicKeyAlgorithmTags.DSA
        || key.getAlgorithm() == PublicKeyAlgorithmTags.ECDSA){
        return false;
    }

    return hasKeyFlags(key, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
}
 
开发者ID:ibm-messaging,项目名称:mq-mft,代码行数:15,代码来源:CryptDecryptUtil.java

示例6: createKeyRingGenerator

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
/**
 * creates and initializes a PGP Key Ring Generator
 *
 * @param userId
 *    the user id to use
 * @param password
 *    the password used for the private key
 * @param keySize
 *    the key size used for the keys
 * @return the initialized key ring generator or null if something goes wrong
 */
private PGPKeyRingGenerator createKeyRingGenerator(String userId, String password, int keySize) {
  LOGGER.trace("createKeyRingGenerator(String, String, int)");
  LOGGER.trace("User ID: {}, Password: {}, Key Size: {}", userId, password == null ? "not set" : "********", keySize);
  PGPKeyRingGenerator generator = null;
  try {
    LOGGER.debug("Creating RSA key pair generator");
    RSAKeyPairGenerator generator1 = new RSAKeyPairGenerator();
    generator1.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), getSecureRandom(), keySize, 12));
    LOGGER.debug("Generating Signing Key Pair");
    BcPGPKeyPair signingKeyPair = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, generator1.generateKeyPair(), new Date());
    LOGGER.debug("Generating Encyption Key Pair");
    BcPGPKeyPair encryptionKeyPair = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, generator1.generateKeyPair(), new Date());
    LOGGER.debug("Generating Signature Key Properties");
    PGPSignatureSubpacketGenerator signatureSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    signatureSubpacketGenerator.setKeyFlags(false, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER);
    signatureSubpacketGenerator.setPreferredSymmetricAlgorithms(false, getPreferredEncryptionAlgorithms());
    signatureSubpacketGenerator.setPreferredHashAlgorithms(false, getPreferredHashingAlgorithms());
    signatureSubpacketGenerator.setPreferredCompressionAlgorithms(false, getPreferredCompressionAlgorithms());

    LOGGER.debug("Generating Encyption Key Properties");
    PGPSignatureSubpacketGenerator encryptionSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    encryptionSubpacketGenerator.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

    LOGGER.info("Creating PGP Key Ring Generator");
    generator = new PGPKeyRingGenerator(PGPPublicKey.RSA_SIGN, signingKeyPair, userId, new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1), signatureSubpacketGenerator.generate(), null, new BcPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA256), new BcPBESecretKeyEncryptorBuilder(getEncryptionAlgorithm()).build(password.toCharArray()));
    generator.addSubKey(encryptionKeyPair, encryptionSubpacketGenerator.generate(), null);
  } catch (PGPException e) {
    LOGGER.error("{}", e.getMessage());
    generator = null;
  }
  return generator;
}
 
开发者ID:sniggle,项目名称:simple-pgp,代码行数:44,代码来源:PGPKeyPairGenerator.java

示例7: getPgpKeyFlags

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private static Set<PgpKeyFlag> getPgpKeyFlags(int keyFlags) {
	final EnumSet<PgpKeyFlag> result = EnumSet.noneOf(PgpKeyFlag.class);

	// Using org.bouncycastle.bcpg.sig.KeyFlags instead of org.bouncycastle.openpgp.PGPKeyFlags, because
	// it seems more complete. Seems OpenPGP did not yet standardize all (CAN_AUTHENTICATE / AUTHENTICATION is missing).

	if ((keyFlags & KeyFlags.CERTIFY_OTHER) != 0)
		result.add(PgpKeyFlag.CAN_CERTIFY);

	if ((keyFlags & KeyFlags.SIGN_DATA) != 0)
		result.add(PgpKeyFlag.CAN_SIGN);

	if ((keyFlags & KeyFlags.AUTHENTICATION) != 0)
		result.add(PgpKeyFlag.CAN_AUTHENTICATE);

	if ((keyFlags & KeyFlags.ENCRYPT_COMMS) != 0)
		result.add(PgpKeyFlag.CAN_ENCRYPT_COMMS);

	if ((keyFlags & KeyFlags.ENCRYPT_STORAGE) != 0)
		result.add(PgpKeyFlag.CAN_ENCRYPT_STORAGE);

	if ((keyFlags & KeyFlags.SPLIT) != 0)
		result.add(PgpKeyFlag.MAYBE_SPLIT);

	if ((keyFlags & KeyFlags.SHARED) != 0)
		result.add(PgpKeyFlag.MAYBE_SHARED);

	return result;
}
 
开发者ID:subshare,项目名称:subshare,代码行数:30,代码来源:BcPgpKey.java

示例8: generateKeyPair

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
public SecretKey generateKeyPair(final String id, final char[] pass) throws CryptoException {
  try {

    // This object generates individual key-pairs.
    final RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
    kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 2048, 12));

    // First create the master (signing) key with the generator.
    final PGPKeyPair keyPair = new BcPGPKeyPair(PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date());

    // Add a self-signature on the id
    final PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
    signhashgen.setKeyFlags(true, KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA | KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
    signhashgen.setPreferredCompressionAlgorithms(false, new int[] { CompressionAlgorithmTags.ZIP });
    signhashgen.setPreferredHashAlgorithms(false, new int[] { HashAlgorithmTags.SHA1 });
    signhashgen.setPreferredSymmetricAlgorithms(false, new int[] { SymmetricKeyAlgorithmTags.AES_256 });
    signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);

    // Create a signature on the encryption subkey.
    final PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
    enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

    // Objects used to encrypt the secret key.

    // Finally, create the keyring itself. The constructor
    // takes parameters that allow it to generate the self
    // signature.
    final PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
    final PBESecretKeyEncryptor secretKeyEncryptor = new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_128, sha1Calc).build(pass);
    final BcPGPContentSignerBuilder contentSigner = new BcPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1);
    final PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, keyPair, id, sha1Calc,
        signhashgen.generate(), null, contentSigner, secretKeyEncryptor);

    // return new SimpleKeyPair(new BcPGPPublicKey(publicKeyRing.getPublicKey()),
    return new BcPGPSecretKey(keyRingGen.generateSecretKeyRing().getSecretKey());
  }
  catch (final Exception e) {
    throw new CryptoException(e);
  }
}
 
开发者ID:hsch,项目名称:bcpg-simple,代码行数:41,代码来源:BcPGPKeyFactory.java

示例9: checkValue

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private void checkValue(int flag, int value)
{
    KeyFlags f = new KeyFlags(true, flag);

    if (f.getFlags() != value)
    {
        fail("flag value mismatch");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:10,代码来源:PGPSignatureTest.java

示例10: maybeUpdateIfEncrypt

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private void maybeUpdateIfEncrypt(PGPSignature sig, PGPPublicKey pk)
{
    if (!hasKeyFlag
        (sig, KeyFlags.ENCRYPT_STORAGE|KeyFlags.ENCRYPT_COMMS)) {
        return;
    }
    long cur = sig.getCreationTime().getTime();
    if ((m_pk != null) && (cur < m_last_ts)) { return; }
    m_pk = pk;
    m_last_ts = cur;
}
 
开发者ID:kbsriram,项目名称:keypan,代码行数:12,代码来源:CPGPUtils.java

示例11: hasKeyFlag

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private final static boolean hasKeyFlag(PGPSignature sig, int flag)
{
    PGPSignatureSubpacketVector hashed = sig.getHashedSubPackets();
    if (hashed == null) { return false; }

    KeyFlags flags = (KeyFlags)
        hashed.getSubpacket(SignatureSubpacketTags.KEY_FLAGS);
    if (flags == null) { return false; }
    return ((flags.getFlags() & flag) != 0);
}
 
开发者ID:kbsriram,项目名称:keypan,代码行数:11,代码来源:CPGPUtils.java

示例12: generateKeyRingGenerator

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
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,代码行数:59,代码来源:RSAGen.java

示例13: generateKeyRingGenerator

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
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,代码行数:78,代码来源:PGPUtils.java

示例14: setKeyFlags

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
public void setKeyFlags(boolean isCritical, int flags)
{
    list.add(new KeyFlags(isCritical, flags));
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:PGPSignatureSubpacketGenerator.java

示例15: generateKeyRingGenerator

import org.bouncycastle.bcpg.sig.KeyFlags; //导入依赖的package包/类
private static PGPKeyRingGenerator generateKeyRingGenerator( String id, char[] pass, int s2kcount, int keySize,
                                                             KeyPair keyPair ) throws PGPException
{
    // 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(), keySize, 12 ) );

    // First create the master (signing) key with the generator.
    PGPKeyPair rsakp_sign = new BcPGPKeyPair( PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date() );
    // Then an encryption subkey.
    PGPKeyPair rsakp_enc = new BcPGPKeyPair( PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date() );

    keyPair.setPrimaryKeyId( Long.toHexString( rsakp_sign.getKeyID() ) );
    keyPair.setPrimaryKeyFingerprint( BytesToHex( rsakp_sign.getPublicKey().getFingerprint() ) );
    keyPair.setSubKeyId( Long.toHexString( rsakp_enc.getKeyID() ) );
    keyPair.setSubKeyFingerprint( BytesToHex( rsakp_enc.getPublicKey().getFingerprint() ) );

    // Add a self-signature on the id
    PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();

    // Add signed metadata on the signature.
    // 1) Declare its purpose
    signhashgen.setKeyFlags( false, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER );
    // 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,
            SymmetricKeyAlgorithmTags.CAST5, SymmetricKeyAlgorithmTags.TRIPLE_DES
    } );
    signhashgen.setPreferredHashAlgorithms( false, new int[] {
            HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512,
            HashAlgorithmTags.SHA224,
    } );
    signhashgen.setPreferredCompressionAlgorithms( false, new int[] {
            CompressionAlgorithmTags.ZLIB, CompressionAlgorithmTags.BZIP2, CompressionAlgorithmTags.ZIP
    } );
    // 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 );

    // bcpg 1.48 exposes this API that includes s2kcount. Earlier
    // versions use a default of 0x60.
    PBESecretKeyEncryptor pske =
            ( new BcPBESecretKeyEncryptorBuilder( PGPEncryptedData.CAST5, sha1Calc, 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 );

    // Add our encryption subkey, together with its signature.
    keyRingGen.addSubKey( rsakp_enc, enchashgen.generate(), null );
    return keyRingGen;
}
 
开发者ID:subutai-io,项目名称:base,代码行数:70,代码来源:PGPEncryptionUtil.java


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