List of usage examples for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags CAST5
int CAST5
To view the source code for org.bouncycastle.bcpg SymmetricKeyAlgorithmTags CAST5.
Click Source Link
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:/*from w w w .j a v a 2 s .c o m*/ throw new PGPException("unknown symmetric algorithm: " + algorithm); } }
From source file:alpha.offsync.security.OpenPGPSecurityUtility.java
License:Apache License
@Override public void encrypt(final OutputStream outputStream, final InputStream inputStream, final String[] keyInfo) { try {/*w ww.j a v a 2s . c o m*/ // = // this.readPublicKey(this.publicKeyRing); final ArmoredOutputStream out = new ArmoredOutputStream(outputStream); try { final BcPGPDataEncryptorBuilder builder = new BcPGPDataEncryptorBuilder( SymmetricKeyAlgorithmTags.CAST5); builder.setSecureRandom(new SecureRandom()); final PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(builder, true); for (final String info : keyInfo) { final PGPPublicKey encKey = this.getEncryptionKey(info); if (encKey != null) { cPk.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(encKey)); } else { OpenPGPSecurityUtility.LOGGER .info("Encryption key for recipient " + info + " could not be found!"); } } final OutputStream cOut = cPk.open(out, new byte[1 << 16]); final PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator( CompressionAlgorithmTags.ZIP); final PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator(); final byte[] buffer = new byte[1 << 16]; final OutputStream pOut = lData.open(comData.open(cOut), PGPLiteralData.BINARY, "", new Date(), buffer); final byte[] buf = new byte[buffer.length]; int len; while ((len = inputStream.read(buf)) > 0) { pOut.write(buf, 0, len); } lData.close(); inputStream.close(); comData.close(); cOut.close(); out.close(); } catch (final PGPException e) { System.err.println(e); if (e.getUnderlyingException() != null) { e.getUnderlyingException().printStackTrace(); } } } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.lyndir.lhunath.opal.crypto.gpg.GPG.java
License:Apache License
/** * PGP Encrypt a stream./*from w ww.ja va 2 s .c om*/ * * @param plainTextStream The stream that contains the plain-text data. * @param publicKey The public key to use for encryption. * @param armoured {@code true}: ASCII armor the encrypted data. * * @return The encrypted data stream. * * @throws NoSuchProviderException * @throws IOException * @throws PGPException */ public static InputStream encrypt(final InputStream plainTextStream, final PGPPublicKey publicKey, final boolean armoured) throws IOException, NoSuchProviderException, PGPException { /* Compress and extract literal data packets that can be encrypted. */ PGPEncryptedDataGenerator encryptedDataGenerator = null; try (ByteArrayOutputStream decryptedStream = new ByteArrayOutputStream(); ByteArrayOutputStream encryptedByteStream = new ByteArrayOutputStream()) { PGPLiteralDataGenerator literalDataGenerator = new PGPLiteralDataGenerator(); PGPCompressedDataGenerator compressor = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZLIB); OutputStream literalStream = literalDataGenerator.open(compressor.open(decryptedStream), PGPLiteralData.BINARY, "", new Date(), new byte[4096]); ByteStreams.copy(plainTextStream, literalStream); compressor.close(); /* Encrypt compressed data. */ encryptedDataGenerator = new PGPEncryptedDataGenerator(SymmetricKeyAlgorithmTags.CAST5, new SecureRandom(), BouncyCastleProvider.PROVIDER_NAME); encryptedDataGenerator.addMethod(publicKey); /* Create the encrypted output stream, armour if necessary. */ OutputStream encryptedStream = encryptedByteStream; if (armoured) encryptedStream = new ArmoredOutputStream(encryptedStream); /* Create and write out the encrypted file. */ OutputStream encryptionStream = encryptedDataGenerator.open(encryptedStream, new byte[4096]); ByteStreams.copy(new ByteArrayInputStream(decryptedStream.toByteArray()), encryptionStream); return new ByteArrayInputStream(encryptedByteStream.toByteArray()); } finally { if (encryptedDataGenerator != null) encryptedDataGenerator.close(); } }
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 www .j a v a2 s.c o m throw new IllegalArgumentException("unknown symmetric algorithm: " + algorithm); } }
From source file:org.sufficientlysecure.keychain.support.KeyringBuilder.java
License:Open Source License
private static SignaturePacket createSignaturePacket(BigInteger signature) { MPInteger[] signatureArray = new MPInteger[] { new MPInteger(signature) }; int signatureType = PGPSignature.POSITIVE_CERTIFICATION; int keyAlgorithm = SignaturePacket.RSA_GENERAL; int hashAlgorithm = HashAlgorithmTags.SHA1; SignatureSubpacket[] hashedData = new SignatureSubpacket[] { new SignatureCreationTime(false, SIGNATURE_DATE), new KeyFlags(false, KeyFlags.CERTIFY_OTHER + KeyFlags.SIGN_DATA), new KeyExpirationTime(false, TimeUnit.DAYS.toSeconds(2)), new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_SYM_ALGS, false, new int[] { SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_128, SymmetricKeyAlgorithmTags.CAST5, SymmetricKeyAlgorithmTags.TRIPLE_DES }), new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_HASH_ALGS, false, new int[] { HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224 }), new PreferredAlgorithms(SignatureSubpacketTags.PREFERRED_COMP_ALGS, false, new int[] { CompressionAlgorithmTags.ZLIB, CompressionAlgorithmTags.BZIP2, CompressionAlgorithmTags.ZIP }), new Features(false, Features.FEATURE_MODIFICATION_DETECTION), createPreferencesSignatureSubpacket() }; SignatureSubpacket[] unhashedData = new SignatureSubpacket[] { new IssuerKeyID(false, false, KEY_ID.toByteArray()) }; byte[] fingerPrint = new BigInteger("522c", 16).toByteArray(); return new SignaturePacket(signatureType, KEY_ID.longValue(), keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerPrint, signatureArray); }
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);//w w w. j av a 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; }