Example usage for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags TWOFISH

List of usage examples for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags TWOFISH

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags TWOFISH.

Prototype

int TWOFISH

To view the source code for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags TWOFISH.

Click Source Link

Usage

From source file:genkeys.java

License:Open Source License

private static String symmetricCipherName(int algorithm) throws PGPException {
    switch (algorithm) {
    case SymmetricKeyAlgorithmTags.NULL:
        return null;
    case SymmetricKeyAlgorithmTags.TRIPLE_DES:
        return "DESEDE";
    case SymmetricKeyAlgorithmTags.IDEA:
        return "IDEA";
    case SymmetricKeyAlgorithmTags.CAST5:
        return "CAST5";
    case SymmetricKeyAlgorithmTags.BLOWFISH:
        return "Blowfish";
    case SymmetricKeyAlgorithmTags.SAFER:
        return "SAFER";
    case SymmetricKeyAlgorithmTags.DES:
        return "DES";
    case SymmetricKeyAlgorithmTags.AES_128:
        return "AES";
    case SymmetricKeyAlgorithmTags.AES_192:
        return "AES";
    case SymmetricKeyAlgorithmTags.AES_256:
        return "AES";
    case SymmetricKeyAlgorithmTags.TWOFISH:
        return "Twofish";
    default://ww  w .j  ava  2  s.  com
        throw new PGPException("unknown symmetric algorithm: " + algorithm);
    }
}

From source file:divconq.pgp.PGPUtil.java

License:Open Source License

public static String getSymmetricCipherName(int algorithm) {
    switch (algorithm) {
    case SymmetricKeyAlgorithmTags.NULL:
        return null;
    case SymmetricKeyAlgorithmTags.TRIPLE_DES:
        return "DESEDE";
    case SymmetricKeyAlgorithmTags.IDEA:
        return "IDEA";
    case SymmetricKeyAlgorithmTags.CAST5:
        return "CAST5";
    case SymmetricKeyAlgorithmTags.BLOWFISH:
        return "Blowfish";
    case SymmetricKeyAlgorithmTags.SAFER:
        return "SAFER";
    case SymmetricKeyAlgorithmTags.DES:
        return "DES";
    case SymmetricKeyAlgorithmTags.AES_128:
        return "AES";
    case SymmetricKeyAlgorithmTags.AES_192:
        return "AES";
    case SymmetricKeyAlgorithmTags.AES_256:
        return "AES";
    case SymmetricKeyAlgorithmTags.CAMELLIA_128:
        return "Camellia";
    case SymmetricKeyAlgorithmTags.CAMELLIA_192:
        return "Camellia";
    case SymmetricKeyAlgorithmTags.CAMELLIA_256:
        return "Camellia";
    case SymmetricKeyAlgorithmTags.TWOFISH:
        return "Twofish";
    default://from w  w  w  .  j  ava  2s  .c om
        throw new IllegalArgumentException("unknown symmetric algorithm: " + algorithm);
    }
}

From source file:org.tramaci.onionmail.PGPKeyGen.java

License:Open Source License

public static PGPKeyRingGenerator generateKeyRingGenerator(String id, char[] pass, int s2kcount, int nBits,
        int certainty, Date when) throws Exception {

    RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
    RSAKeyGenerationParameters kgp = new RSAKeyGenerationParameters(DEFAULT_PUBEXP, new SecureRandom(), nBits,
            certainty);//from   w  ww .  ja  va 2  s  .co  m
    kpg.init(kgp);
    PGPKeyPair rsakpSign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, kpg.generateKeyPair(), when);
    PGPKeyPair rsakpEnc = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, kpg.generateKeyPair(), when);
    PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();

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

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

    signhashgen.setPreferredHashAlgorithms(false, new int[] { HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1,
            HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224 });

    signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
    PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
    enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

    PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
    PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);

    PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc,
            s2kcount)).build(pass);

    PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, rsakpSign, id,
            sha1Calc, signhashgen.generate(), null,
            new BcPGPContentSignerBuilder(rsakpSign.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
            pske);

    keyRingGen.addSubKey(rsakpEnc, enchashgen.generate(), null);
    return keyRingGen;
}