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

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

Introduction

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

Prototype

public SHA256Digest() 

Source Link

Document

Standard constructor

Usage

From source file:com.github.horrorho.inflatabledonkey.crypto.key.KeyID.java

License:Open Source License

static byte[] id(byte[] data) {
    // SHA256 truncated to 20 bytes. 
    Digest digest = new SHA256Digest();
    byte[] out = new byte[digest.getDigestSize()];

    digest.update(data, 0, data.length);
    digest.doFinal(out, 0);// w ww .  j  ava  2s.  c o m

    return Arrays.copyOf(out, 20);
}

From source file:com.github.horrorho.inflatabledonkey.crypto.key.SignatureAssistant.java

License:Open Source License

public static Optional<Digest> digestForSignature(Signature signature) {
    switch (signature.type()) {
    case 0x01:/*from   www.ja  va  2 s  . c  o m*/
        return Optional.ofNullable(new SHA256Digest());

    case 0x02:
        return Optional.ofNullable(new SHA512Digest());

    default:
        logger.warn("-- digestForSignature() - unsupported signature type: {}", signature);
        return Optional.empty();
    }
}

From source file:com.github.horrorho.inflatabledonkey.crypto.srp.SRPFactory.java

License:Open Source License

public static SRPClient rfc5054(SecureRandom random) {
    BigInteger N = new BigInteger(1, Hex.decode(DEFAULT_PRIME_HEX));
    Digest digest = new SHA256Digest();
    return new SRPClient(random, digest, N, BigInteger.valueOf(2));
}

From source file:com.github.horrorho.inflatabledonkey.file.KeyBlobCurve25519Unwrap.java

License:Open Source License

public static Optional<byte[]> curve25519Unwrap(byte[] myPublicKey, byte[] myPrivateKey, byte[] otherPublicKey,
        byte[] wrappedKey) {

    SHA256Digest sha256 = new SHA256Digest();

    byte[] shared = Curve25519.agreement(otherPublicKey, myPrivateKey);
    logger.debug("-- curve25519Unwrap() - shared agreement: 0x{}", Hex.toHexString(shared));

    // Stripped down NIST SP 800-56A KDF.
    byte[] counter = new byte[] { 0x00, 0x00, 0x00, 0x01 };
    byte[] hash = new byte[sha256.getDigestSize()];

    sha256.reset();//from   w w w  . ja va  2s . c o  m
    sha256.update(counter, 0, counter.length);
    sha256.update(shared, 0, shared.length);
    sha256.update(otherPublicKey, 0, otherPublicKey.length);
    sha256.update(myPublicKey, 0, myPublicKey.length);
    sha256.doFinal(hash, 0);

    logger.debug("-- curve25519Unwrap() - kek: {}", Hex.toHexString(hash));
    return RFC3394Wrap.unwrapAES(hash, wrappedKey);
}

From source file:com.github.horrorho.inflatabledonkey.pcs.key.SignatureAssistant.java

License:Open Source License

static Optional<Digest> digest(Signature signature) {
    switch (signature.type()) {
    case 0x01://w  w w .j  a  va2  s .c om
        return Optional.ofNullable(new SHA256Digest());

    case 0x02:
        return Optional.ofNullable(new SHA512Digest());

    default:
        logger.warn("-- digest() - unsupported signature type: {}", signature);
        return Optional.empty();
    }
}

From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileKeyAssistant.java

License:Open Source License

public static Optional<byte[]> curve25519Unwrap(byte[] myPublicKey, byte[] myPrivateKey, byte[] otherPublicKey,
        byte[] wrappedKey) {

    SHA256Digest sha256 = new SHA256Digest();

    byte[] shared = Curve25519.agreement(otherPublicKey, myPrivateKey);
    byte[] pad = new byte[] { 0x00, 0x00, 0x00, 0x01 };
    byte[] hash = new byte[sha256.getDigestSize()];

    sha256.reset();//from   ww w .ja va2 s . c o  m
    sha256.update(pad, 0, pad.length);
    sha256.update(shared, 0, shared.length);
    sha256.update(otherPublicKey, 0, otherPublicKey.length);
    sha256.update(myPublicKey, 0, myPublicKey.length);
    sha256.doFinal(hash, 0);

    return AESWrap.unwrap(hash, wrappedKey);
}

From source file:com.github.horrorho.liquiddonkey.cloud.store.ChunkDecrypter.java

License:Open Source License

/**
 * Returns a new instance.//from w  w w  .  j  ava 2s  .com
 *
 * @return a new instance, not null
 */
public static ChunkDecrypter create() {
    return new ChunkDecrypter(new CFBBlockCipher(new AESEngine(), 128), new SHA256Digest());
}

From source file:com.ipseorama.webapp.baddtls.CertHolder.java

public static String getPrint(org.bouncycastle.asn1.x509.Certificate fpc) throws IOException {
    StringBuilder b = new StringBuilder();
    byte[] enc = fpc.getEncoded();
    SHA256Digest d = new SHA256Digest();
    d.update(enc, 0, enc.length);//from  w  w  w.  j a va  2 s  .c  o m
    byte[] result = new byte[d.getDigestSize()];
    d.doFinal(result, 0);
    for (byte r : result) {
        String dig = Integer.toHexString((0xff) & r).toUpperCase();
        if (dig.length() == 1) {
            b.append('0');
        }
        b.append(dig).append(":");
    }
    b.deleteCharAt(b.length() - 1);
    return b.toString();
}

From source file:com.joyent.manta.client.crypto.SupportedHmacsLookupMap.java

License:Open Source License

/**
 * Wraps a getInstance call as a {@link Supplier} so that we can return a
 * new HMAC instance for every value of this map.
 *
 * @param algorithm algorithm to instantiate HMAC instance as
 * @return supplier wrapping getInstance call to get HMAC instance
 *//*from  ww w.  j  a  va 2 s.c o m*/
private static Supplier<HMac> hmacSupplierByName(final String algorithm) {
    return () -> {
        if (algorithm.equalsIgnoreCase("HmacMD5")) {
            return new HMac(new FastMD5Digest());
        } else if (algorithm.equalsIgnoreCase("HmacSHA1")) {
            return new HMac(new SHA1Digest());
        } else if (algorithm.equalsIgnoreCase("HmacSHA256")) {
            return new HMac(new SHA256Digest());
        } else if (algorithm.equalsIgnoreCase("HmacSHA384")) {
            return new HMac(new SHA384Digest());
        } else if (algorithm.equalsIgnoreCase("HmacSHA512")) {
            return new HMac(new SHA512Digest());
        } else {
            String msg = String.format("Hmac algorithm [%s] not supported", algorithm);
            throw new MantaClientEncryptionException(msg);
        }
    };
}

From source file:com.licel.jcardsim.crypto.MessageDigestImpl.java

License:Apache License

public MessageDigestImpl(byte algorithm) {
    this.algorithm = algorithm;
    blockSize = 64;// w w  w  . j  a  v a 2s . c  o  m
    componentStartIdx = 1;
    switch (algorithm) {
    case ALG_SHA:
        engine = new SHA1Digest();
        digestClass = engine.getClass();
        break;
    case ALG_MD5:
        engine = new MD5Digest();
        digestClass = engine.getClass();
        break;
    case ALG_RIPEMD160:
        engine = new RIPEMD160Digest();
        digestClass = engine.getClass();
        componentStartIdx = 0;
        break;
    case ALG_SHA_256:
        engine = new SHA256Digest();
        digestClass = engine.getClass();
        break;
    case ALG_SHA_384:
        engine = new SHA384Digest();
        blockSize = 128;
        byteCountFieldName = "byteCount1";
        digestClass = engine.getClass().getSuperclass();
        break;
    case ALG_SHA_512:
        engine = new SHA512Digest();
        blockSize = 128;
        byteCountFieldName = "byteCount1";
        digestClass = engine.getClass().getSuperclass();
        break;
    default:
        CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM);
        break;
    }
    componentSize = (byte) (blockSize == 64 ? 4 : 8);
    componentCount = (byte) (engine.getDigestSize() / componentSize);
}