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:com.yacme.ext.oxsit.cust_it.comp.security.cert.X509CertDisplayBase_IT.java

License:Open Source License

protected void initThumbPrints() {
    //obtain a byte block of the entire certificate data
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {//from  w ww  .  j  av a 2  s . c o  m
        dOut.writeObject(m_aX509);
        byte[] certBlock = bOut.toByteArray();

        //now compute the certificate SHA1 & MD5 digest
        SHA1Digest digsha1 = new SHA1Digest();
        digsha1.update(certBlock, 0, certBlock.length);
        byte[] hashsha1 = new byte[digsha1.getDigestSize()];
        digsha1.doFinal(hashsha1, 0);
        m_sSHA1Thumbprint = Helpers.printHexBytes(hashsha1);
        MD5Digest digmd5 = new MD5Digest();
        digmd5.update(certBlock, 0, certBlock.length);
        byte[] hashmd5 = new byte[digmd5.getDigestSize()];
        digmd5.doFinal(hashmd5, 0);
        m_sMD5Thumbprint = Helpers.printHexBytes(hashmd5);
    } catch (IOException e) {
        m_aLogger.severe("initThumbPrints", e);
    }
}

From source file:com.zipato.controller.User.java

private static String getSHA1(String value) {
    Digest digest = new SHA1Digest();
    digest.update(value.getBytes(), 0, value.getBytes().length);
    byte[] resBuf = new byte[digest.getDigestSize()];
    digest.doFinal(resBuf, 0);//from  ww w.  jav  a2 s  . co m

    return new String(Hex.encode(resBuf));
}

From source file:common.crypto.bouncycastle.CCryptoSHABC.java

License:Open Source License

@Override
public void initialize(CryptoTypes.ESHAMode eMode) {
    switch (eMode) {
    case SHA1:/* w w  w  .j  a va2  s.  c  o  m*/
        m_digest = new SHA1Digest();
        break;
    case SHA256:
        m_digest = new SHA256Digest();
        break;
    case SHA512:
        m_digest = new SHA512Digest();
    }
}

From source file:crypto.util.hash.Hash.java

public String generateHash(File file, Boolean replace) throws FileNotFoundException, IOException {
    String hash = null;/*  w ww .  j a va2  s .c  o  m*/
    //converting file to bytes
    FileInputStream fis = null;

    fis = new FileInputStream(file);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];

    for (int readNum; (readNum = fis.read(buf)) != -1;) {
        bos.write(buf, 0, readNum); //no doubt here is 0
    }

    byte[] bytes = bos.toByteArray();

    Security.addProvider(new BouncyCastleProvider());
    Digest messageDigestObj = new SHA1Digest();
    byte[] digest = new byte[messageDigestObj.getDigestSize()];
    messageDigestObj.update(bytes, 0, bytes.length);
    messageDigestObj.doFinal(digest, 0);
    hash = new String(Base64.encode(digest));

    if (replace) {
        hash = hash.replace("/", "").replace("=", "");
    }

    return hash;
}

From source file:crypto.util.hash.Hash.java

public String generateHash(String data, Boolean replace) {
    String hash = null;/*  ww w. jav  a 2s . c o m*/
    Security.addProvider(new BouncyCastleProvider());
    Digest messageDigestObj = new SHA1Digest();
    byte[] digest = new byte[messageDigestObj.getDigestSize()];
    messageDigestObj.update(data.getBytes(), 0, data.getBytes().length);
    messageDigestObj.doFinal(digest, 0);

    hash = new String(Base64.encode(digest));

    if (replace) {
        hash = hash.replace("/", "").replace("=", "");
    }

    return hash;
}

From source file:crypto.util.hash.Hash.java

public String generateHashHex(String data) {

    String hash = null;/*from  w  w  w . j a  va  2 s .  co m*/
    Security.addProvider(new BouncyCastleProvider());
    Digest messageDigestObj = new SHA1Digest();
    byte[] digest = new byte[messageDigestObj.getDigestSize()];
    messageDigestObj.update(data.getBytes(), 0, data.getBytes().length);
    messageDigestObj.doFinal(digest, 0);

    hash = new String(Hex.encode(digest));

    return hash;
}

From source file:cybervillains.ca.ThumbprintUtil.java

License:Open Source License

/**
 * Generates a SHA1 thumbprint of a certificate for long-term mapping.
 * //from w  w  w.jav  a2 s.  com
 * @param cert
 * @return
 * @throws CertificateEncodingException
 */
public static String getThumbprint(final X509Certificate cert) throws CertificateEncodingException {

    if (cert == null) {
        return null;
    }

    byte[] rawOctets = cert.getEncoded();

    SHA1Digest digest = new SHA1Digest();

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

    digest.update(rawOctets, 0, rawOctets.length);

    digest.doFinal(digestOctets, 0);

    return new String(Base64.encode(digestOctets));
}

From source file:de.tsenger.animamea.crypto.KeyDerivationFunction.java

License:Open Source License

/**
 * //  ww w  .  j a v a 2  s. co  m
 * Das MRZ-Passwort besteht aus dem SHA1-Wert der Dokumentennummer +
 * Geburtsdatum + Gltigkeitsdatum (jeweils mit Prfziffer)
 * 
 * @param documentNr
 *            Dokumentennummer plus Prfziffer
 * @param dateOfBirth
 *            Geburtsdatum aus der MRZ plus Prfziffer
 * @param dateOfExpiry
 *            Gltigkeitsdatum aus der MRZ plus Prfziffer
 * @return K = SHA-1(Serial Number||Date of Birth||Date of Expiry)
 */
public static byte[] getMRZBytes(String documentNr, String dateOfBirth, String dateOfExpiry) {
    String mrzInfo = documentNr + dateOfBirth + dateOfExpiry;
    byte[] passwordBytes = mrzInfo.getBytes();

    byte[] K = new byte[20];

    SHA1Digest sha1 = new SHA1Digest();
    sha1.update(passwordBytes, 0, passwordBytes.length);
    sha1.doFinal(K, 0);

    return K;
}

From source file:de.tsenger.animamea.crypto.KeyDerivationFunction.java

License:Open Source License

/**
 * Erzeugt 3DES Schlssel/*from  ww w. j ava  2 s.  c  o  m*/
 * 
 * @return 112bit-3DES-Schlssel in 24 Bytes mit korrekten Parity-Bits
 */
public byte[] getDESedeKey() {

    byte[] checksum = new byte[20];

    SHA1Digest sha1 = new SHA1Digest();
    sha1.update(mergedData, 0, mergedData.length);
    sha1.doFinal(checksum, 0);

    byte[] ka = new byte[8];
    byte[] kb = new byte[8];

    System.arraycopy(checksum, 0, ka, 0, ka.length);
    System.arraycopy(checksum, 8, kb, 0, kb.length);

    // Adjust Parity-Bits
    adjustParity(ka, 0);
    adjustParity(kb, 0);

    byte[] key = new byte[24];
    System.arraycopy(ka, 0, key, 0, 8);
    System.arraycopy(kb, 0, key, 8, 8);
    System.arraycopy(ka, 0, key, 16, 8);

    return key;

}

From source file:de.tsenger.animamea.crypto.KeyDerivationFunction.java

License:Open Source License

/**
 * Erzeugt AES-128 Schlssel/*  w  w  w  . j  a v  a 2 s  .  co  m*/
 * 
 * @return Schlssel als Byte-Array
 */
public byte[] getAES128Key() {

    byte[] checksum = new byte[20];

    SHA1Digest sha1 = new SHA1Digest();
    sha1.update(mergedData, 0, mergedData.length);
    sha1.doFinal(checksum, 0);

    // keydata = H(K||r||c)
    // keydata sind die ersten 16 Byte der Hashfunktion ber "mergedData"
    byte[] keydata = new byte[16];
    System.arraycopy(checksum, 0, keydata, 0, 16);
    return keydata;
}