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:dorkbox.util.crypto.Crypto.java

License:Apache License

public static byte[] hashFileSHA1(File file) {
    SHA1Digest digest = new SHA1Digest();
    return hashFile(file, digest, null);
}

From source file:dorkbox.util.crypto.CryptoDSA.java

License:Apache License

/**
 * The message will have the SHA1 hash calculated and used for the signature.
 * <p/>/*  www .j  a v a2 s.c  o m*/
 * Note: this is here just for keeping track of how this is done. This should NOT be used, and instead use ECC crypto.
 * <p/>
 * The returned signature is the {r,s} signature array.
 */
public static BigInteger[] generateSignature(DSAPrivateKeyParameters privateKey, SecureRandom secureRandom,
        byte[] message) {
    ParametersWithRandom param = new ParametersWithRandom(privateKey, secureRandom);

    DSASigner dsa = new DSASigner();

    dsa.init(true, param);

    SHA1Digest sha1Digest = new SHA1Digest();
    byte[] checksum = new byte[sha1Digest.getDigestSize()];

    sha1Digest.update(message, 0, message.length);
    sha1Digest.doFinal(checksum, 0);

    return dsa.generateSignature(checksum);
}

From source file:dorkbox.util.crypto.CryptoDSA.java

License:Apache License

/**
 * The message will have the SHA1 hash calculated and used for the signature.
 * <p/>//from w w  w.ja  v  a 2s. c  o  m
 * Note: this is here just for keeping track of how this is done. This should NOT be used, and instead use ECC crypto.
 *
 * @param signature
 *                 is the {r,s} signature array.
 *
 * @return true if the signature is valid
 */
public static boolean verifySignature(DSAPublicKeyParameters publicKey, byte[] message,
        BigInteger[] signature) {
    SHA1Digest sha1Digest = new SHA1Digest();
    byte[] checksum = new byte[sha1Digest.getDigestSize()];

    sha1Digest.update(message, 0, message.length);
    sha1Digest.doFinal(checksum, 0);

    DSASigner dsa = new DSASigner();

    dsa.init(false, publicKey);

    return dsa.verifySignature(checksum, signature[0], signature[1]);
}

From source file:dorkbox.util.crypto.RsaTest.java

License:Apache License

@SuppressWarnings("deprecation")
@Test/*from w w w . j  av  a2  s .c  o  m*/
public void Rsa() {
    byte[] bytes = "hello, my name is inigo montoya".getBytes();

    AsymmetricCipherKeyPair key = CryptoRSA.generateKeyPair(new SecureRandom(entropySeed.getBytes()), 1024);

    RSAKeyParameters public1 = (RSAKeyParameters) key.getPublic();
    RSAPrivateCrtKeyParameters private1 = (RSAPrivateCrtKeyParameters) key.getPrivate();

    RSAEngine engine = new RSAEngine();
    SHA1Digest digest = new SHA1Digest();
    OAEPEncoding rsaEngine = new OAEPEncoding(engine, digest);

    // test encrypt/decrypt
    byte[] encryptRSA = CryptoRSA.encrypt(rsaEngine, public1, bytes, logger);
    byte[] decryptRSA = CryptoRSA.decrypt(rsaEngine, private1, encryptRSA, logger);

    if (Arrays.equals(bytes, encryptRSA)) {
        fail("bytes should not be equal");
    }

    if (!Arrays.equals(bytes, decryptRSA)) {
        fail("bytes not equal");
    }

    // test signing/verification
    PSSSigner signer = new PSSSigner(engine, digest, digest.getDigestSize());

    byte[] signatureRSA = CryptoRSA.sign(signer, private1, bytes, logger);
    boolean verify = CryptoRSA.verify(signer, public1, signatureRSA, bytes);

    if (!verify) {
        fail("failed signature verification");
    }
}

From source file:edu.biu.scapi.primitives.hash.bc.BcSHA1.java

License:Open Source License

/** 
 * Passes the digest SHA1 of BC to the super class which does the hash computation. 
 *//*  w w w  . j a va  2s  .  c om*/
public BcSHA1() {
    //passes the digest SHA1 of BC. 
    super(new SHA1Digest());
}

From source file:edu.tamu.tcat.crypto.bouncycastle.internal.DigestTypeMap.java

License:Apache License

public static Digest getDigest(DigestType type) {
    Objects.requireNonNull(type);
    switch (type) {
    case SHA1://w ww. j a v  a2 s .com
        return new SHA1Digest();
    case SHA224:
        return new SHA224Digest();
    case SHA256:
        return new SHA256Digest();
    case SHA384:
        return new SHA384Digest();
    case SHA512:
        return new SHA512Digest();
    default:
        throw new IllegalArgumentException();
    }
}

From source file:edu.vt.middleware.crypt.digest.SHA1.java

License:Open Source License

/** Creates an uninitialized instance of an SHA1 digest. */
public SHA1() {
    super(new SHA1Digest());
}

From source file:edu.vt.middleware.crypt.digest.SHA1.java

License:Open Source License

/**
 * Creates a new SHA1 digest that may optionally be initialized with random
 * data.//from w w  w . jav  a2 s .  c  om
 *
 * @param  randomize  True to randomize initial state of digest, false
 * otherwise.
 */
public SHA1(final boolean randomize) {
    super(new SHA1Digest());
    if (randomize) {
        setRandomProvider(new SecureRandom());
        setSalt(getRandomSalt());
    }
}

From source file:edu.vt.middleware.crypt.digest.SHA1.java

License:Open Source License

/**
 * Creates a new SHA1 digest and initializes it with the given salt.
 *
 * @param  salt  Salt data used to initialize digest computation.
 *///  w  w w.ja va2s  . c om
public SHA1(final byte[] salt) {
    super(new SHA1Digest());
    setSalt(salt);
}

From source file:eu.betaas.taas.securitymanager.common.ec.operator.SHA1DigestCalculator.java

License:Apache License

public byte[] getDigest() {
    byte[] bytes = bOut.toByteArray();

    bOut.reset();/*from ww  w  .j av a2s. c  o  m*/

    Digest sha1 = new SHA1Digest();

    sha1.update(bytes, 0, bytes.length);

    byte[] digest = new byte[sha1.getDigestSize()];

    sha1.doFinal(digest, 0);

    return digest;
}