@frida/crypto
Version:
Node.js's crypto module for Frida
36 lines (35 loc) • 1.03 kB
JavaScript
import { Buffer } from "buffer";
export default {
createHash,
};
export function createHash(type) {
return new Hash(new Checksum(type));
}
export class Hash {
constructor(checksum) {
this.checksum = checksum;
}
update(data, inputEncoding) {
// TODO: TypedArray
if (data instanceof DataView)
throw new Error("DataView not yet supported");
if (inputEncoding !== undefined)
throw new Error("inputEncoding not yet supported");
if (data instanceof Buffer)
this.checksum.update(data.buffer);
else
this.checksum.update(data);
return this;
}
digest(encoding = "binary") {
if (encoding === "hex")
return this.checksum.getString();
const rawDigest = Buffer.from(this.checksum.getDigest());
if (encoding === "binary")
return rawDigest;
return rawDigest.toString(encoding);
}
copy() {
throw new Error("copy() not yet supported");
}
}