Example usage for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest

List of usage examples for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest.

Prototype

public SHA1Digest() 

Source Link

Document

Standard constructor

Usage

From source file:org.bunkr.core.streams.input.BlockReaderInputStream.java

License:Open Source License

public BlockReaderInputStream(File path, int blockSize, FileInventoryItem target) {
    super();//  w  ww .j av  a2  s .c  o  m
    this.filePath = path;
    this.blockSize = blockSize;
    this.dataLength = target.getSizeOnDisk();
    this.blocks = target.getBlocks().copy();
    this.buffer = new byte[blockSize];
    this.checkHashOnFinish = true;
    this.expectedDigest = target.getIntegrityHash();
    this.digest = new SHA1Digest();

    long blockDataLength = ((long) blocks.size()) * blockSize;
    if (dataLength > blockDataLength)
        throw new IllegalArgumentException("File dataLength is greater than block count * block size");

    this.cursor = this.blockSize;
    this.bytesConsumed = 0;
}

From source file:org.bunkr.core.streams.output.BlockWriterOutputStream.java

License:Open Source License

public BlockWriterOutputStream(File path, int blockSize, FileInventoryItem target,
        IBlockAllocationManager blockAllocMan)

        throws FileNotFoundException {
    super();/*w w w .jav a2  s  .co m*/
    this.blockSize = blockSize;
    this.target = target;
    this.blockAllocMan = blockAllocMan;
    this.blockAllocMan.clearAllocation();

    this.buffer = new byte[this.blockSize];
    this.blockCursor = 0;
    this.bytesWritten = 0;
    this.partiallyFlushed = false;

    this.inputFile = new RandomAccessFile(path, "rw");
    this.inputFileChannel = this.inputFile.getChannel();
    this.digester = new SHA1Digest();
}

From source file:org.candlepin.util.X509CRLStreamWriter.java

License:Open Source License

protected static Digest createDigest(AlgorithmIdentifier digAlg) throws CryptoException {
    Digest dig;// w w  w . ja v a2s .c om

    if (digAlg.getAlgorithm().equals(OIWObjectIdentifiers.idSHA1)) {
        dig = new SHA1Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha224)) {
        dig = new SHA224Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha256)) {
        dig = new SHA256Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha384)) {
        dig = new SHA384Digest();
    } else if (digAlg.getAlgorithm().equals(NISTObjectIdentifiers.id_sha512)) {
        dig = new SHA384Digest();
    } else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md5)) {
        dig = new MD5Digest();
    } else if (digAlg.getAlgorithm().equals(PKCSObjectIdentifiers.md4)) {
        dig = new MD4Digest();
    } else {
        throw new CryptoException("Cannot recognize digest.");
    }

    return dig;
}

From source file:org.cryptacular.generator.HOTPGenerator.java

License:Open Source License

@Override
protected Digest getDigest() {
    return new SHA1Digest();
}

From source file:org.cryptacular.spec.DigestSpec.java

License:Open Source License

/**
 * Creates a new digest instance./*from   w ww  . ja v  a2 s.  c om*/
 *
 * @return  Digest instance.
 */
@Override
public Digest newInstance() {
    final Digest digest;
    if ("GOST3411".equalsIgnoreCase(algorithm)) {
        digest = new GOST3411Digest();
    } else if ("MD2".equalsIgnoreCase(algorithm)) {
        digest = new MD2Digest();
    } else if ("MD4".equalsIgnoreCase(algorithm)) {
        digest = new MD4Digest();
    } else if ("MD5".equalsIgnoreCase(algorithm)) {
        digest = new MD5Digest();
    } else if ("RIPEMD128".equalsIgnoreCase(algorithm) || "RIPEMD-128".equalsIgnoreCase(algorithm)) {
        digest = new RIPEMD128Digest();
    } else if ("RIPEMD160".equalsIgnoreCase(algorithm) || "RIPEMD-160".equalsIgnoreCase(algorithm)) {
        digest = new RIPEMD160Digest();
    } else if ("RIPEMD256".equalsIgnoreCase(algorithm) || "RIPEMD-256".equalsIgnoreCase(algorithm)) {
        digest = new RIPEMD256Digest();
    } else if ("RIPEMD320".equalsIgnoreCase(algorithm) || "RIPEMD-320".equalsIgnoreCase(algorithm)) {
        digest = new RIPEMD320Digest();
    } else if ("SHA1".equalsIgnoreCase(algorithm) || "SHA-1".equalsIgnoreCase(algorithm)) {
        digest = new SHA1Digest();
    } else if ("SHA224".equalsIgnoreCase(algorithm) || "SHA-224".equalsIgnoreCase(algorithm)) {
        digest = new SHA224Digest();
    } else if ("SHA256".equalsIgnoreCase(algorithm) || "SHA-256".equalsIgnoreCase(algorithm)) {
        digest = new SHA256Digest();
    } else if ("SHA384".equalsIgnoreCase(algorithm) || "SHA-384".equalsIgnoreCase(algorithm)) {
        digest = new SHA384Digest();
    } else if ("SHA512".equalsIgnoreCase(algorithm) || "SHA-512".equalsIgnoreCase(algorithm)) {
        digest = new SHA512Digest();
    } else if ("SHA3".equalsIgnoreCase(algorithm) || "SHA-3".equalsIgnoreCase(algorithm)) {
        digest = new SHA3Digest(size);
    } else if ("Tiger".equalsIgnoreCase(algorithm)) {
        digest = new TigerDigest();
    } else if ("Whirlpool".equalsIgnoreCase(algorithm)) {
        digest = new WhirlpoolDigest();
    } else {
        throw new IllegalStateException("Unsupported digest algorithm " + algorithm);
    }
    return digest;
}

From source file:org.cryptacular.util.HashUtil.java

License:Open Source License

/**
 * Produces the SHA-1 hash of the given data.
 *
 * @param  data  Data to hash. See {@link #hash(Digest, Object...)} for
 *               supported inputs./*from   w w w .j a va 2 s .  c om*/
 *
 * @return  20-byte array containing hash output.
 *
 * @see  #hash(Digest, Object...)
 */
public static byte[] sha1(final Object... data) {
    return hash(new SHA1Digest(), data);
}

From source file:org.cryptacular.util.HashUtilTest.java

License:Open Source License

@DataProvider(name = "salted-hashes")
public Object[][] getSaltedHashData() {
    return new Object[][] {
            { new SHA1Digest(), new Object[] { ByteUtil.toBytes("deoxyribonucleic acid"), }, 1,
                    "0aDM5g/qqfVV/8MIqkTKQaklWSg=", },
            { new SHA1Digest(), new Object[] { ByteUtil.toBytes("protoporphyrin-9"), SALT, }, 1,
                    "6SafHIoTusYN6dnK1pxx7udaBLA=", },
            { new SHA256Digest(), new Object[] { SALT, ByteUtil.toBytes("N-arachidonoylethanolamine"), }, 5,
                    "RWIg3BIXdqZPI9C7PFvSn62miU3L9ponVZLvKmC9XlQ=", }, };
}

From source file:org.cryptacular.util.HashUtilTest.java

License:Open Source License

@DataProvider(name = "hash-compare")
public Object[][] getHashCompareData() {
    return new Object[][] {
            { new SHA1Digest(), CodecUtil.b64("7fyOZXGp+gKMziV/2Px7RIMkxyI2O1H8"), 1,
                    ByteUtil.toBytes("password"), },
            { new SHA1Digest(), CodecUtil.b64("0aDM5g/qqfVV/8MIqkTKQaklWSg="), 1,
                    ByteUtil.toBytes("deoxyribonucleic acid"), }, };
}

From source file:org.cryptacular.util.HashUtilTest.java

License:Open Source License

@DataProvider(name = "salted-hash-compare")
public Object[][] getSaltedHashCompareData() {
    return new Object[][] {
            { new SHA1Digest(), new SaltedHash(CodecUtil.b64("7fyOZXGp+gKMziV/2Px7RIMkxyI2O1H8"), 20, true), 1,
                    true, ByteUtil.toBytes("password"), }, };
}

From source file:org.ejbca.ui.cli.ca.CaRenewCACommand.java

License:Open Source License

private static String computePublicKeyHash(final PublicKey publicKey) {
    final Digest digest = new SHA1Digest();
    final byte[] hash = new byte[digest.getDigestSize()];
    final byte[] data = publicKey.getEncoded();
    digest.update(data, 0, data.length);
    digest.doFinal(hash, 0);/*from   w ww  .  j a v a2  s. co  m*/
    return new String(Hex.encode(hash));
}