First question on the new forum for me, literally cant find an answer anywhere so here goes…
I have have a sketch that uploads a file to my Wordpress site using an HTTP Post Request, the process uses basic access authentication (Basic Auth). Now i know this is not the most secure way of completing this so i would like to use OAuth 1 authorisation instead. I have everything setup in WordPress on the server side and have most of the required parameters, the only one that is proving a problem is the request HMAC-SHA1 signature. From what i have read i should be able to import a combo of Java libraries and make use of something similar to this code on github (first and last examples).
import java.security.SignatureException;
import java.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class HMAC_SHA1 {
public static String Signature(String xData, String AppKey) throws java.security.SignatureException {
try {
final Base64.Encoder encoder = Base64.getEncoder();
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(AppKey.getBytes("UTF-8"),"HmacSHA1");
// get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(xData.getBytes("UTF-8"));
String result = encoder.encodeToString(rawHmac);
return result;
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : "+ e.getMessage());
}
}
}
Only issue here is i cant figure out how to do that sadly. I have imported the required .jar files into my sketch and have copied over the code from github but after staring at it for ages i just cant figure out how i would use the HMAC_SHA1 class in my sketch with the variables/parameters i have already. I think i already have the xData and AppKey information if that makes any sense.
Any help would be really appreciated although i realise it’s a big ask, not your normal sort of processing thing.
Cheers