/** * * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * encode the input data producing a base 64 encoded byte array. * * @return a byte array containing the base 64 encoded data. */ public static byte[] encode( byte[] data) { return encode(data, 0, data.length); }
/** {@inheritDoc} */ @Override public String base64Encode(byte[] bytes) { try { return new String(Base64.encode(bytes), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** {@inheritDoc} */ @Override public String base64Encode(byte[] bytes) { try { return new String(Base64.encode(bytes), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * <p>base64Encode.</p> * * @param bytes an array of byte. * @return a {@link java.lang.String} object. */ public static String base64Encode(byte[] bytes) { try { return new String(Base64.encode(bytes), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
public String encrypt(final String plainText, final String password) { if (this.cipher == null) { initWithPassword(password); } try { cipher.init(Cipher.ENCRYPT_MODE, key, spec); byte[] encrypted = cipher.doFinal(plainText.getBytes("UTF-8")); return new String(Base64.encode(encrypted), "UTF-8"); } catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e) { throw new RuntimeException(e); } }
public static String encode(byte[] input) { return Strings.fromByteArray(org.spongycastle.util.encoders.Base64.encode(input)); } }
@Override public String encrypt(String plainString) { if (plainString == null) { throw new IllegalArgumentException("PlainString must not be null"); } try { byte[] plainStringBytes = plainString.getBytes(ENCODING); byte[] encodedText = new byte[plainStringBytes.length]; salsa20Engine.processBytes(plainStringBytes, 0, plainStringBytes.length, encodedText, 0); byte[] protectedBuffer = Base64.encode(encodedText); return new String(protectedBuffer, ENCODING); } catch (UnsupportedEncodingException e) { throw new UnsupportedOperationException(MSG_UNKNOWN_UTF8_ENCODING, e); } }
/** * * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 // bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = v; System.arraycopy(ByteUtils.BigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(ByteUtils.BigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 // bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
/** * * @return - */ public String toBase64() { byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = v; System.arraycopy(bigIntegerToBytes(this.r, 32), 0, sigData, 1, 32); System.arraycopy(bigIntegerToBytes(this.s, 32), 0, sigData, 33, 32); return new String(Base64.encode(sigData), Charset.forName("UTF-8")); }
public static String toBase64String( byte[] data, int off, int length) { byte[] encoded = encode(data, off, length); return Strings.fromByteArray(encoded); }
private void writeEncoded(byte[] bytes) throws IOException { bytes = Base64.encode(bytes); for (int i = 0; i < bytes.length; i += buf.length) { int index = 0; while (index != buf.length) { if ((i + index) >= bytes.length) { break; } buf[index] = (char)bytes[i + index]; index++; } this.write(buf, 0, index); this.newLine(); } }
private void writeEncoded(byte[] bytes) throws IOException { bytes = Base64.encode(bytes); for (int i = 0; i < bytes.length; i += buf.length) { int index = 0; while (index != buf.length) { if ((i + index) >= bytes.length) { break; } buf[index] = (char)bytes[i + index]; index++; } this.write(buf, 0, index); this.newLine(); } }
private void writeEncoded(byte[] bytes) throws IOException { bytes = Base64.encode(bytes); for (int i = 0; i < bytes.length; i += buf.length) { int index = 0; while (index != buf.length) { if ((i + index) >= bytes.length) { break; } buf[index] = (char)bytes[i + index]; index++; } this.write(buf, 0, index); this.newLine(); } }
@Test public void testMagic() throws Exception { String message = "{\"hello\":\"world\"}"; String expected1 = "LxR+2CipfgdIdi4EZgNOKTT+96WbppXnPZZjdZJ2vwA="; String expected2 = "skkJOHg9L6/1OVztbUohjcvVR3cNdRDZ/OJOUdQI41M="; byte[] magic = MetadataUtil.magic(message.getBytes(), null); Assert.assertEquals(expected1, new String(Base64.encode(magic))); byte[] nextMagic = MetadataUtil.magic(message.getBytes(), magic); Assert.assertEquals(expected2, new String(Base64.encode(nextMagic))); } }
@Test public void testGetMessage() throws Exception { String message = "{\"hello\":\"world\"}"; String expected1 = "eyJoZWxsbyI6IndvcmxkIn0="; String expected2 = "LxR+2CipfgdIdi4EZgNOKTT+96WbppXnPZZjdZJ2vwCTojlxqRTl6svwqNJRVM2jCcPBxy+7mRTUfGDzy2gViA=="; byte[] result = MetadataUtil.message(message.getBytes("utf-8"), null); Assert.assertEquals(expected1, new String(Base64.encode(result))); byte[] magic = MetadataUtil.magic(message.getBytes(), null); byte[] nextResult = MetadataUtil.message(message.getBytes(), magic); Assert.assertEquals(expected2, new String(Base64.encode(nextResult))); }