List of usage examples for org.bouncycastle.util.encoders Base64 encode
public static int encode(byte[] data, OutputStream out) throws IOException
From source file:com.gpfcomics.android.cryptnos.SiteParameters.java
License:Open Source License
/** * Given a byte array, return a Base64-encoded string of its value. This * method was added because there's no simple, single method way to do * this, and we need to perform this task multiple times. Abstraction * and code reuse is good. ;)/*from w w w. jav a 2 s . c o m*/ * @param bytes The byte array to encode. * @return A Base64-encoded string. */ private static String base64String(byte[] bytes) { // Asbestos underpants: try { // Seriously? There's no easier way to do this? Not even with // Bouncy Castle's stuff? We'll take advantage of Bouncy Castle // doing the brunt of the work, but we still need to go through // the trouble of using a ByteArrayOutputStream to do all this. ByteArrayOutputStream baos = new ByteArrayOutputStream(); Base64.encode(bytes, baos); baos.flush(); baos.close(); return baos.toString(); } // Not sure what could occur here, but just in case, we'll return // a simple null if anything blows up. catch (Exception e) { return null; } }