Example usage for org.bouncycastle.operator RuntimeOperatorException RuntimeOperatorException

List of usage examples for org.bouncycastle.operator RuntimeOperatorException RuntimeOperatorException

Introduction

In this page you can find the example usage for org.bouncycastle.operator RuntimeOperatorException RuntimeOperatorException.

Prototype

public RuntimeOperatorException(String msg) 

Source Link

Usage

From source file:org.xipki.common.HashCalculator.java

License:Open Source License

public static byte[] hash(final HashAlgoType hashAlgoType, final byte[] data) {
    ParamChecker.assertNotNull("hashAlgoType", hashAlgoType);
    ParamChecker.assertNotNull("data", data);
    if (mdsMap.containsKey(hashAlgoType) == false) {
        throw new IllegalArgumentException("unknown hash algo " + hashAlgoType);
    }//from w  w w  . j a va  2s. co m

    BlockingDeque<MessageDigest> mds = mdsMap.get(hashAlgoType);

    MessageDigest md = null;
    for (int i = 0; i < 3; i++) {
        try {
            md = mds.poll(10, TimeUnit.SECONDS);
            break;
        } catch (InterruptedException e) {
        }
    }

    if (md == null) {
        throw new RuntimeOperatorException("could not get idle MessageDigest");
    }

    try {
        md.reset();
        return md.digest(data);
    } finally {
        mds.addLast(md);
    }
}

From source file:org.xipki.commons.security.FpIdCalculator.java

License:Open Source License

/**
 * Hash the data and returns the first 8 bytes of the hash value.
 * @return long represented of the first 8 bytes
 *///ww w.j  a  v a2 s  . c o m
public static long hash(final byte[] data) {
    ParamUtil.requireNonNull("data", data);

    Digest md = null;
    for (int i = 0; i < 3; i++) {
        try {
            md = MDS.poll(10, TimeUnit.SECONDS);
            break;
        } catch (InterruptedException ex) { // CHECKSTYLE:SKIP
        }
    }

    if (md == null) {
        throw new RuntimeOperatorException("could not get idle MessageDigest");
    }

    try {
        md.reset();
        md.update(data, 0, data.length);
        byte[] bytes = new byte[md.getDigestSize()];
        md.doFinal(bytes, 0);

        return bytesToLong(bytes);
    } finally {
        MDS.addLast(md);
    }
}

From source file:org.xipki.commons.security.HashCalculator.java

License:Open Source License

public static byte[] hash(final HashAlgoType hashAlgoType, final byte[] data) {
    ParamUtil.requireNonNull("hashAlgoType", hashAlgoType);
    ParamUtil.requireNonNull("data", data);
    if (!MDS_MAP.containsKey(hashAlgoType)) {
        throw new IllegalArgumentException("unknown hash algo " + hashAlgoType);
    }//w  ww. j a va2s  .  co  m

    BlockingDeque<Digest> mds = MDS_MAP.get(hashAlgoType);

    Digest md = null;
    for (int i = 0; i < 3; i++) {
        try {
            md = mds.poll(10, TimeUnit.SECONDS);
            break;
        } catch (InterruptedException ex) { // CHECKSTYLE:SKIP
        }
    }

    if (md == null) {
        throw new RuntimeOperatorException("could not get idle MessageDigest");
    }

    try {
        md.reset();
        md.update(data, 0, data.length);
        byte[] bytes = new byte[md.getDigestSize()];
        md.doFinal(bytes, 0);
        return bytes;
    } finally {
        mds.addLast(md);
    }
}