use of org.apache.commons.codec.binary.Base64.encodeBase64String in project hadoop by apache.
the class Signer method computeSignature.
/**
* Returns then signature of a string.
*
* @param secret The secret to use
* @param str string to sign.
*
* @return the signature for the string.
*/
protected String computeSignature(byte[] secret, String str) {
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(str.getBytes(Charset.forName("UTF-8")));
md.update(secret);
byte[] digest = md.digest();
return new Base64(0).encodeToString(digest);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
}
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project camel by apache.
the class SigningProcessor method process.
public void process(Exchange exchange) throws Exception {
Signature service = initSignatureService(exchange);
calculateSignature(exchange, service);
byte[] signature = service.sign();
Message in = exchange.getIn();
clearMessageHeaders(in);
Message out = exchange.getOut();
out.copyFrom(in);
out.setHeader(config.getSignatureHeaderName(), new Base64().encode(signature));
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project amos-ss17-alexa by c-i-ber.
the class SignedRequestsHelper method hmac.
/**
* Compute the HMAC.
*
* @param stringToSign String to compute the HMAC over.
* @return base64-encoded hmac value.
*/
private String hmac(String stringToSign) {
String signature = null;
byte[] data;
byte[] rawHmac;
try {
data = stringToSign.getBytes(UTF8_CHARSET);
rawHmac = mac.doFinal(data);
Base64 encoder = new Base64();
signature = new String(encoder.encode(rawHmac));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(UTF8_CHARSET + " is unsupported!", e);
}
return signature;
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project nem2-sdk-java by nemtech.
the class Base64Encoder method getBytes.
/**
* Converts a string to a byte array.
*
* @param base64String The input Base64 string.
* @return The output byte array.
*/
public static byte[] getBytes(final String base64String) {
final Base64 codec = new Base64();
final byte[] encodedBytes = StringEncoder.getBytes(base64String);
if (!codec.isInAlphabet(encodedBytes, true)) {
throw new IllegalArgumentException("malformed base64 string passed to getBytes");
}
return codec.decode(encodedBytes);
}
use of org.apache.commons.codec.binary.Base64.encodeBase64String in project tmdm-studio-se by Talend.
the class PasswordUtil method decryptPasswordBase64.
public static String decryptPasswordBase64(String encodedPassword) {
Base64 base64 = new Base64();
byte[] debytes = null;
String decodeStr = null;
debytes = base64.decode(encodedPassword.getBytes());
decodeStr = new String(debytes);
return decodeStr;
}
Aggregations