Java源码示例:org.spongycastle.crypto.Digest

示例1
/**
 * @param data - message to hash
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
    Digest digest = new RIPEMD160Digest();
    if (data != null) {
        byte[] resBuf = new byte[digest.getDigestSize()];
        digest.update(data, 0, data.length);
        digest.doFinal(resBuf, 0);
        return resBuf;
    }
    throw new NullPointerException("Can't hash a NULL value");
}
 
示例2
private static byte[] getHmac(byte[] secret, byte[] data, Digest algorithm) {
    HMac hmac = new HMac(algorithm);
    hmac.init(new KeyParameter(secret));
    byte[] result = new byte[hmac.getMacSize()];
    hmac.update(data, 0, data.length);
    hmac.doFinal(result, 0);
    return result;
}
 
示例3
private static byte[] getMultiHmac(byte[] secret, byte[] data, int bytes, Digest algorithm) {
    byte[] nuData = data;
    byte[] output = new byte[bytes];
    int size = 0;
    while (size < bytes) {
        nuData = getHmac(secret, nuData, algorithm);
        byte[] preOutput = getHmac(secret, combine(nuData, data), algorithm);
        System.arraycopy(preOutput, 0, output, size, Math.min(bytes - size, preOutput.length));
        size += preOutput.length;
    }
    return output;
}
 
示例4
/**
 * @param data - message to hash
 *
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
  Digest digest = new RIPEMD160Digest();
  if (data != null) {
    byte[] resBuf = new byte[digest.getDigestSize()];
    digest.update(data, 0, data.length);
    digest.doFinal(resBuf, 0);
    return resBuf;
  }
  throw new NullPointerException("Can't hash a NULL value");
}
 
示例5
public static String sha3(byte[] bytes, int bitLength) {
    Digest digest = new SHA3Digest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return Hex.encode(rsData);
}
 
示例6
public static byte[] sha3bytes(byte[] bytes, int bitLength) {
    Digest digest = new SHA3Digest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return rsData;
}
 
示例7
public static String keccak(byte[] bytes, int bitLength) {
    Digest digest = new KeccakDigest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return Hex.encode(rsData);
}
 
示例8
public static byte[] keccakBytes(byte[] bytes, int bitLength) {
    Digest digest = new KeccakDigest(bitLength);
    digest.update(bytes, 0, bytes.length);
    byte[] rsData = new byte[digest.getDigestSize()];
    digest.doFinal(rsData, 0);
    return rsData;
}
 
示例9
/**
 * @param data - message to hash
 * @return - reipmd160 hash of the message
 */
public static byte[] ripemd160(byte[] data) {
    Digest digest = new RIPEMD160Digest();
    if (data != null) {
        byte[] resBuf = new byte[digest.getDigestSize()];
        digest.update(data, 0, data.length);
        digest.doFinal(resBuf, 0);
        return resBuf;
    }
    throw new NullPointerException("Can't hash a NULL value");
}
 
示例10
private static byte[] getHmac(byte[] secret, byte[] data, Digest algorithm) {
    HMac hmac = new HMac(algorithm);
    hmac.init(new KeyParameter(secret));
    byte[] result = new byte[hmac.getMacSize()];
    hmac.update(data, 0, data.length);
    hmac.doFinal(result, 0);
    return result;
}
 
示例11
private static byte[] getMultiHmac(byte[] secret, byte[] data, int bytes, Digest algorithm) {
    byte[] nuData = data;
    byte[] output = new byte[bytes];
    int size = 0;
    while (size < bytes) {
        nuData = getHmac(secret, nuData, algorithm);
        byte[] preOutput = getHmac(secret, combine(nuData, data), algorithm);
        System.arraycopy(preOutput, 0, output, size, Math.min(bytes - size, preOutput.length));
        size += preOutput.length;
    }
    return output;
}
 
示例12
/**
 * Base constructor.
 *
 * @param digest digest to build the HMAC on.
 */
public MyHMacDSAKCalculator(Digest digest) {
  this.hMac = new HMac(digest);
  this.V = new byte[hMac.getMacSize()];
  this.K = new byte[hMac.getMacSize()];
}
 
示例13
public ConcatKDFBytesGenerator(Digest digest) {
    this(1, digest);
}
 
示例14
/**
 * return the underlying digest.
 */
public Digest getDigest()
{
    return digest;
}
 
示例15
public MGF1BytesGeneratorExt(Digest digest, int counterStart) {
    this.digest = digest;
    this.hLen = digest.getDigestSize();
    this.counterStart = counterStart;
}
 
示例16
public Digest getDigest() {
    return this.digest;
}
 
示例17
/**
 * Construct a KDF Parameters generator.
 * <p>
 * 
 * @param counterStart
 *            value of counter.
 * @param digest
 *            the digest to be used as the source of derived keys.
 */
protected ConcatKDFBytesGenerator(int counterStart, Digest digest)
{
    this.counterStart = counterStart;
    this.digest = digest;
}