Saturday, February 27, 2010

Some Crypto in Anger - using JCE and BouncyCastle JCE Provider


OutputStream out = new ObjectOutputStream(new FileOutputStream("encrypter.key"));
// Serialize the secret to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();

ObjectOutput objectOutput = new ObjectOutputStream(bos);
 objectOutput.writeObject(secret);

objectOutput.close();

// Get the bytes of the serialized object and use them as the inputstream

InputStream is = new ByteArrayInputStream(bos.toByteArray());
streamEncrypter.encrypt(is, out);

No comments: