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

Method Hash

java/lib/src/main/java/io/github/ccxt/base/Crypto.java:158–180  ·  view source on GitHub ↗
(Object request2, Object hash, Object digest2)

Source from the content-addressed store, hash-verified

156 // ====================================================
157
158 public static Object Hash(Object request2, Object hash, Object digest2) {
159 String algorithm = (hash == null) ? null : toString(hash);
160 String digest = (digest2 == null) ? "hex" : toString(digest2);
161
162 // If the caller already passed raw bytes, hash those directly.
163 // Otherwise treat the value as a string and hash its UTF-8 encoding.
164 byte[] input = (request2 instanceof byte[]) ? (byte[]) request2 : toUtf8(request2);
165
166 byte[] signature;
167 switch (algorithm) {
168 case "sha256": signature = digestBytes("SHA-256", input); break;
169 case "sha512": signature = digestBytes("SHA-512", input); break;
170 case "sha384": signature = digestBytes("SHA-384", input); break;
171 case "sha1": signature = digestBytes("SHA-1", input); break;
172 case "md5": signature = digestBytes("MD5", input); break;
173 case "keccak":
174 case "sha3": signature = keccakDigest(input); break;
175 default: throw new IllegalArgumentException("Unsupported hash algo: " + algorithm);
176 }
177
178 if ("binary".equals(digest)) return signature;
179 return "hex".equals(digest) ? binaryToHex(signature) : BinaryToBase64(signature);
180 }
181
182 private static byte[] digestBytes(String algo, byte[] data) {
183 try {

Callers 2

hashMethod · 0.95
hashMethod · 0.95

Calls 7

toStringMethod · 0.95
toUtf8Method · 0.95
digestBytesMethod · 0.95
keccakDigestMethod · 0.95
binaryToHexMethod · 0.95
BinaryToBase64Method · 0.95
equalsMethod · 0.45

Tested by

no test coverage detected