/** * @return The post body as a string, assuming UTF-8 encoding. * TODO: We should probably tolerate other encodings, based on the * Content-Type header. */ public String getPostBodyAsString() { return CharsetUtil.newUtf8String(postBody); }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
/** * Decode a base-64 encoded string. */ @Functions.Expose(prefix = "osx", names = {"decodeBase64"}) public static String decodeBase64(String text) { if (text == null) { return null; } // TODO: allow a charset to be passed in? return CharsetUtil.newUtf8String(Base64.decodeBase64(CharsetUtil.getUtf8Bytes(text))); }
/** * Calculate hash value for response and update metadata value (DATA_HASH) * @return hash value */ public String getHash(HttpResponse response) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(response.getResponseAsBytes()); byte[] md5val = md5.digest(); return CharsetUtil.newUtf8String(Base32.encodeBase32(md5val)); } catch (NoSuchAlgorithmException e) { // Should not happen if (LOG.isLoggable(Level.INFO)) { LOG.logp(Level.INFO, classname, "getHash", MessageKeys.ERROR_GETTING_MD5); } } return null; }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
private Map<String, String> deserialize(byte[] plain) { String base = CharsetUtil.newUtf8String(plain); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i=0; i < items.length; ) { String key = Utf8UrlCoder.decode(items[i++]); String val = Utf8UrlCoder.decode(items[i++]); map.put(key, val); } return map; } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
public String wrap(Map<String, String> in) throws BlobCrypterException { try { byte[] encoded = serialize(in); byte[] cipherText = Crypto.aes128cbcEncrypt(cipherKey, encoded); byte[] hmac = Crypto.hmacSha(hmacKey, cipherText,hmacType.getName()); byte[] b64 = Base64.encodeBase64URLSafe(Bytes.concat(cipherText, hmac)); return CharsetUtil.newUtf8String(b64); } catch (GeneralSecurityException e) { throw new BlobCrypterException(e); } }
byte[] body = IOUtils.toByteArray(base.getPostBody()); byte[] hash = DigestUtils.sha(body); String b64 = CharsetUtil.newUtf8String(Base64.encodeBase64(hash)); params.add(new Parameter(OAuthConstants.OAUTH_BODY_HASH, b64)); } catch (IOException e) {