Hi, I'm trying to create a fingerprint to send to a credit card processor (authorizenet). I'm using the JCE and the code below Is all I could come up with looking online and the API.
I cannot seem to figure out how to use MY OWN key that the gateway I need to connect to provided me. All the examples I see online generate the key and I can't find any examples where you use your own key?
public String HMAC(String values, String key){
String output = "";
try {
//Generate a key for the HMAC-MD5 keyed-hashing algorithm; see RFC 2104
//In practice, you would save this key.
//KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5");
//SecretKey key = keyGen.generateKey();
SecretKey key = "AUNSH8FfjkDKSHJBCD"; // <----- how can I get this to compile?
// Create a MAC object using HMAC-MD5 and initialize with key
Mac mac = Mac.getInstance(key.getAlgorithm());
mac.init(key);
// Encode the string into bytes using utf-8 and digest it
byte[] utf8 = values.getBytes("UTF8");
byte[] digest = mac.doFinal(utf8);
// If desired, convert the digest into a string
String digestB64 = new sun.misc.BASE64Encoder().encode(digest);
output += digestB64;
} catch (InvalidKeyException e) {
} catch (NoSuchAlgorithmException e) {
} catch (UnsupportedEncodingException e) {
}
return output;
}
thanks