1 13 14 package org.ejbca.util; 15 16 import java.io.ByteArrayOutputStream ; 17 18 19 26 public class Base64 { 27 28 34 public static byte[] encode(byte[] data) { 35 return encode(data, true); 36 } 37 38 45 public static byte[] encode(byte[] data, boolean splitlines) { 46 byte[] bytes = org.bouncycastle.util.encoders.Base64.encode(data); 47 if (!splitlines) { 48 return bytes; 49 } 50 51 ByteArrayOutputStream os = new ByteArrayOutputStream (); 53 for (int i = 0; i < bytes.length; i += 64) { 54 if ((i + 64) < bytes.length) { 55 os.write(bytes, i, 64); 56 os.write('\n'); 57 } else { 58 os.write(bytes, i, bytes.length - i); 59 } 60 } 61 return os.toByteArray(); 62 } 63 64 public static byte[] decode(byte[] bytes) { 65 return org.bouncycastle.util.encoders.Base64.decode(bytes); 66 } 67 68 } 69 | Popular Tags |