MCPcopy Index your code
hub / github.com/ccxt/ccxt / Hmac

Method Hmac

java/lib/src/main/java/io/github/ccxt/base/Crypto.java:116–138  ·  view source on GitHub ↗
(Object request2, Object secret2, Object algorithm2, String digest)

Source from the content-addressed store, hash-verified

114 // ====================================================
115
116 public static String Hmac(Object request2, Object secret2, Object algorithm2, String digest) {
117 byte[] request = (request2 instanceof String) ? toUtf8(request2) : (byte[]) request2;
118 byte[] secret = (secret2 instanceof String) ? toUtf8(secret2) : (byte[]) secret2;
119
120 if (digest == null) {
121 digest = "hex"; // default
122 }
123
124 String algo = "md5";
125 if (algorithm2 != null) {
126 algo = toString(algorithm2); // pass "sha256"/"sha512"/"sha384"/"md5"
127 }
128
129 byte[] sig;
130 switch (algo) {
131 case "sha256": sig = hmac("HmacSHA256", request, secret); break;
132 case "sha512": sig = hmac("HmacSHA512", request, secret); break;
133 case "sha384": sig = hmac("HmacSHA384", request, secret); break;
134 case "md5": sig = hmac("HmacMD5", request, secret); break;
135 default: throw new IllegalArgumentException("Unsupported HMAC algo: " + algo);
136 }
137 return "hex".equals(digest) ? binaryToHex(sig) : BinaryToBase64(sig);
138 }
139
140 private static byte[] hmac(String jceName, byte[] data, byte[] key) {
141 try {

Callers 3

hmacMethod · 0.95
hmacMethod · 0.95
JwtMethod · 0.95

Calls 6

toUtf8Method · 0.95
toStringMethod · 0.95
hmacMethod · 0.95
binaryToHexMethod · 0.95
BinaryToBase64Method · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected