Example usage for org.bouncycastle.crypto.digests RIPEMD160Digest getDigestSize

List of usage examples for org.bouncycastle.crypto.digests RIPEMD160Digest getDigestSize

Introduction

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

Prototype

public int getDigestSize() 

Source Link

Usage

From source file:AmazonDynamoDBSample.java

License:Open Source License

private static void oneTimeAddCitations() {

    String jsonString = "";

    try {//  w  ww  .j a  v a  2  s.co  m
        jsonString = readFile("./json/citations.json", StandardCharsets.UTF_8);
    } catch (IOException e) {
        System.out.println(e);
    }

    try {
        JSONObject rootObject = new JSONObject(jsonString); // Parse the JSON to a JSONObject
        JSONArray rows = rootObject.getJSONArray("stuff"); // Get all JSONArray rows

        System.out.println("row lengths: " + rows.length());

        set1 = new HashSet<>();

        for (int j = 0; j < rows.length(); j++) { // Iterate each element in the elements array
            JSONObject element = rows.getJSONObject(j); // Get the element object

            int id = element.getInt("id");
            int citationNumber = element.getInt("citation_number");
            String citationDate = " ";
            Boolean isCitationDateNull = element.isNull("citation_date");
            if (!isCitationDateNull)
                citationDate = element.getString("citation_date");
            String firstName = element.getString("first_name");
            String lastName = element.getString("last_name");
            String firstLastName = firstName + lastName;
            firstLastName = firstLastName.toLowerCase();
            set1.add(firstLastName);

            //System.out.println(firstLastName);
            String dob = " ";
            Boolean isDobNull = element.isNull("date_of_birth");
            if (!isDobNull) {
                dob = element.getString("date_of_birth");
                dob = (dob.split(" "))[0];
            }

            // pick a ssn from list
            String ssn = ssnList.get(ssnCounter);
            ssnCounter--;
            ssnHashMap.put(firstLastName, ssn);

            System.out.println(firstLastName + " " + ssn);

            // compute salt
            final Random ran = new SecureRandom();
            byte[] salt = new byte[32];
            ran.nextBytes(salt);
            String saltString = Base64.encodeBase64String(salt);

            //System.out.println("saltstring: " + saltString);
            saltHashMap.put(firstLastName, saltString);

            // compute ripemd160 hash of ssn + salt
            String saltPlusSsn = saltString + ssn;
            //System.out.println("salt plus ssn: " + saltPlusSsn);

            String resultingHash = "";
            try {
                byte[] r = saltPlusSsn.getBytes("US-ASCII");
                RIPEMD160Digest d = new RIPEMD160Digest();
                d.update(r, 0, r.length);
                byte[] o = new byte[d.getDigestSize()];
                d.doFinal(o, 0);
                ByteArrayOutputStream baos = new ByteArrayOutputStream(40);
                Hex.encode(o, baos);
                resultingHash = new String(baos.toByteArray(), StandardCharsets.UTF_8);

                hashedssnHashMap.put(firstLastName, resultingHash);
            } catch (UnsupportedEncodingException e) {
                System.out.println(e);
            } catch (IOException i) {
                System.out.println(i);
            }

            String fldob = firstLastName + dob;
            String da = " ";
            Boolean isDaNull = element.isNull("defendant_address");
            if (!isDaNull)
                da = element.getString("defendant_address");
            String dc = " ";
            Boolean isDcNull = element.isNull("defendant_city");
            if (!isDcNull)
                dc = element.getString("defendant_city");
            String ds = " ";
            Boolean isDsNull = element.isNull("defendant_state");
            if (!isDsNull)
                ds = element.getString("defendant_state");
            String dln = " ";
            Boolean isDlnNull = element.isNull("drivers_license_number");
            if (!isDlnNull)
                dln = element.getString("drivers_license_number");
            String cd = " ";
            Boolean isCdNull = element.isNull("court_date");
            if (!isCdNull)
                cd = element.getString("court_date");
            String cl = " ";
            Boolean isClNull = element.isNull("court_location");
            if (!isClNull)
                cl = element.getString("court_location");
            String ca = " ";
            Boolean isCaNull = element.isNull("court_address");
            if (!isCaNull)
                ca = element.getString("court_address");
            /*
            Map<String, AttributeValue> item = newCitationItem(citationNumber, citationDate, firstName, lastName, firstLastName, dob, fldob, resultingHash, da, dc, ds, dln, cd, cl, ca);
            PutItemRequest putItemRequest = new PutItemRequest("citations-table", item);
            PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
            */
        }
    } catch (JSONException e) {
        // JSON Parsing error
        e.printStackTrace();
    }
}

From source file:AmazonDynamoDBSample.java

License:Open Source License

private static void oneTimeAddWarrants() {

    String jsonString = "";

    try {//from w  w  w  . j  a  v  a2 s . com
        jsonString = readFile("./json/warrants.json", StandardCharsets.UTF_8);
    } catch (IOException e) {
        System.out.println(e);
    }

    try {
        JSONObject rootObject = new JSONObject(jsonString); // Parse the JSON to a JSONObject
        JSONArray rows = rootObject.getJSONArray("stuff"); // Get all JSONArray rows

        //System.out.println("row lengths: " + rows.length());

        set2 = new HashSet<>();

        for (int j = 0; j < rows.length(); j++) { // Iterate each element in the elements array
            JSONObject element = rows.getJSONObject(j); // Get the element object

            String defendant = element.getString("Defendant");

            String strarr[] = defendant.split(" ");
            String temp = strarr[1];
            int len = strarr[0].length();
            strarr[0] = strarr[0].substring(0, len - 1);
            strarr[1] = strarr[0];
            strarr[0] = temp;

            String firstLast = strarr[0] + strarr[1];
            firstLast = firstLast.toLowerCase();

            set2.add(firstLast);
            //System.out.println(firstLast);

            int zipCode = 0;
            Boolean isZipCodeNull = element.isNull("ZIP Code");
            if (!isZipCodeNull)
                zipCode = element.getInt("ZIP Code");
            String dob = element.getString("Date of Birth");
            String caseNumber = element.getString("Case Number");

            String firstLastDOB = firstLast + dob;

            // pick a ssn from list
            String ssn = ssnList.get(ssnCounter);
            ssnCounter--;
            ssnHashMap.put(firstLast, ssn);

            // compute salt
            final Random ran = new SecureRandom();
            byte[] salt = new byte[32];
            ran.nextBytes(salt);
            String saltString = Base64.encodeBase64String(salt);

            //System.out.println("saltstring: " + saltString);
            saltHashMap.put(firstLast, saltString);

            // compute ripemd160 hash of ssn + salt
            String saltPlusSsn = saltString + ssn;
            //System.out.println("salt plus ssn: " + saltPlusSsn);

            String resultingHash = "";
            try {
                byte[] r = saltPlusSsn.getBytes("US-ASCII");
                RIPEMD160Digest d = new RIPEMD160Digest();
                d.update(r, 0, r.length);
                byte[] o = new byte[d.getDigestSize()];
                d.doFinal(o, 0);
                ByteArrayOutputStream baos = new ByteArrayOutputStream(40);
                Hex.encode(o, baos);
                resultingHash = new String(baos.toByteArray(), StandardCharsets.UTF_8);

                hashedssnHashMap.put(firstLast, resultingHash);
            } catch (UnsupportedEncodingException e) {
                System.out.println(e);
            } catch (IOException i) {
                System.out.println(i);
            }

            //compareNames();

            Map<String, AttributeValue> item = newWarrantItem(firstLast, firstLastDOB, resultingHash, defendant,
                    zipCode, dob, caseNumber);
            PutItemRequest putItemRequest = new PutItemRequest("warrants-table", item);
            PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);

        }
    } catch (JSONException e) {
        // JSON Parsing error
        e.printStackTrace();
    }
}

From source file:Crypto.ServerTools.java

private static String generateUserId(Key k) {
    //https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
    byte[] publicKey = k.getEncoded();
    RIPEMD160Digest d = new RIPEMD160Digest();
    byte[] USER_VERSION_NUMBER = bigIntToByteArray(000);
    byte[] firstRound = publicKey;
    d.update(firstRound, 0, firstRound.length);
    byte[] secondRound = new byte[d.getDigestSize()];
    d.doFinal(secondRound, 0);/*  w  ww  . j  a v a 2s.co  m*/
    byte[] thirdRound = KeyGen.concancateByteArrays(USER_VERSION_NUMBER, secondRound);
    byte[] fourthRound = HashUtils.hashSha256(thirdRound);
    byte[] fifthRound = Arrays.copyOfRange(HashUtils.hashSha256(fourthRound), 0, 4);
    byte[] sixthRound = KeyGen.concancateByteArrays(fourthRound, fifthRound);
    return Base58.encode(sixthRound);
}

From source file:Crypto.ServerTools.java

private static String generateNodeId(Key k) {
    //https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
    byte[] publicKey = k.getEncoded();
    RIPEMD160Digest d = new RIPEMD160Digest();
    byte[] NODE_VERSION_NUMBER = bigIntToByteArray(010);
    byte[] firstRound = publicKey;
    d.update(firstRound, 0, firstRound.length);
    byte[] secondRound = new byte[d.getDigestSize()];
    d.doFinal(secondRound, 0);/*from ww  w  .  j  a  va 2  s . c  o m*/
    byte[] thirdRound = KeyGen.concancateByteArrays(NODE_VERSION_NUMBER, secondRound);
    byte[] fourthRound = HashUtils.hashSha256(thirdRound);
    byte[] fifthRound = Arrays.copyOfRange(HashUtils.hashSha256(fourthRound), 0, 4);
    byte[] sixthRound = KeyGen.concancateByteArrays(fourthRound, fifthRound);
    return Base58.encode(sixthRound);
}

From source file:HashMe.RipeMD160.java

License:Apache License

public static byte[] Enc(String data) throws Exception {
    byte[] r = data.getBytes();
    RIPEMD160Digest d = new RIPEMD160Digest();
    d.update(r, 0, r.length);/* w ww  .  j  a  va  2  s  .c o m*/
    byte[] o = new byte[d.getDigestSize()];
    d.doFinal(o, 0);
    return Hex.encode(o);
}

From source file:it.nibbles.javacoin.script.ScriptImpl.java

License:Open Source License

private byte[] digestRIPEMD160(byte[] data) {
    RIPEMD160Digest ripeDigest = new RIPEMD160Digest();
    ripeDigest.update(data, 0, data.length);
    byte[] hash = new byte[ripeDigest.getDigestSize()]; // Should be actually 20 bytes (160 bits)
    ripeDigest.doFinal(hash, 0);//  www . j a v  a 2 s. com
    return hash;
}

From source file:org.jcryptool.visual.hashing.views.HashingView.java

License:Open Source License

private String computeHash(String hashName, String inputText, Text hashText) {
    hash = hash.getName(hashName);/*ww w . j  a va 2s. c  o m*/
    byte[] digest = null;
    switch (hash) {
    case MD2:
        MD2Digest md2 = new MD2Digest();
        md2.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[md2.getDigestSize()];
        md2.doFinal(digest, 0);

        break;
    case MD4:
        MD4Digest md4 = new MD4Digest();
        md4.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[md4.getDigestSize()];
        md4.doFinal(digest, 0);

        break;
    case MD5:
        MD5Digest md5 = new MD5Digest();
        md5.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[md5.getDigestSize()];
        md5.doFinal(digest, 0);

        break;
    case SHA1:
        SHA1Digest sha1 = new SHA1Digest();
        sha1.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha1.getDigestSize()];
        sha1.doFinal(digest, 0);

        break;
    case SHA256:
        SHA256Digest sha256 = new SHA256Digest();
        sha256.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha256.getDigestSize()];
        sha256.doFinal(digest, 0);

        break;
    case SHA512:
        SHA512Digest sha512 = new SHA512Digest();
        sha512.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha512.getDigestSize()];
        sha512.doFinal(digest, 0);

        break;
    case SHA3_224:
        SHA3.Digest224 sha3_224 = new SHA3.Digest224();
        sha3_224.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha3_224.getDigestLength()];
        digest = sha3_224.digest();

        break;
    case SHA3_256:
        SHA3.Digest256 sha3_256 = new SHA3.Digest256();
        sha3_256.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha3_256.getDigestLength()];
        digest = sha3_256.digest();

        break;
    case SHA3_384:
        SHA3.Digest384 sha3_384 = new SHA3.Digest384();
        sha3_384.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha3_384.getDigestLength()];
        digest = sha3_384.digest();

        break;
    case SHA3_512:
        SHA3.Digest512 sha3_512 = new SHA3.Digest512();
        sha3_512.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sha3_512.getDigestLength()];
        digest = sha3_512.digest();

        break;
    case SKEIN_256:
        Skein.Digest_256_256 skein_256 = new Skein.Digest_256_256();
        skein_256.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[skein_256.getDigestLength()];
        digest = skein_256.digest();

        break;
    case SKEIN_512:
        Skein.Digest_512_512 skein_512 = new Skein.Digest_512_512();
        skein_512.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[skein_512.getDigestLength()];
        digest = skein_512.digest();

        break;
    case SKEIN_1024:
        Skein.Digest_1024_1024 skein_1024 = new Skein.Digest_1024_1024();
        skein_1024.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[skein_1024.getDigestLength()];
        digest = skein_1024.digest();

        break;
    case RIPEMD160:
        RIPEMD160Digest ripemd160 = new RIPEMD160Digest();
        ripemd160.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[ripemd160.getDigestSize()];
        ripemd160.doFinal(digest, 0);

        break;
    case SM3:
        SM3Digest sm3 = new SM3Digest();
        sm3.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[sm3.getDigestSize()];
        sm3.doFinal(digest, 0);

        break;
    case TIGER:
        TigerDigest tiger = new TigerDigest();
        tiger.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[tiger.getDigestSize()];
        tiger.doFinal(digest, 0);

        break;
    case GOST3411:
        GOST3411Digest gost3411 = new GOST3411Digest();
        gost3411.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[gost3411.getDigestSize()];
        gost3411.doFinal(digest, 0);

        break;
    case WHIRLPOOL:
        WhirlpoolDigest whirlpool = new WhirlpoolDigest();
        whirlpool.update(inputText.getBytes(), 0, inputText.getBytes().length);
        digest = new byte[whirlpool.getDigestSize()];
        whirlpool.doFinal(digest, 0);

        break;
    default:
        break;
    }

    String hashHexValue = new String(Hex.encode(digest));
    if (btnHexadezimal.getSelection()) {
        String hashValueOutput = hashHexValue.toUpperCase().replaceAll(".{2}", "$0 "); //$NON-NLS-1$ //$NON-NLS-2$
        hashText.setText(hashValueOutput);
    } else if (btnDezimal.getSelection()) {
        String hashValue = hexToDecimal(hashHexValue);
        hashValue = hashValue.replaceAll(".{3}", "$0 "); //$NON-NLS-1$ //$NON-NLS-2$
        hashText.setText(hashValue);
    } else if (btnBinary.getSelection()) {
        String hashValue = hexToBinary(hashHexValue);
        hashValue = hashValue.replaceAll(".{8}", "$0#"); //$NON-NLS-1$ //$NON-NLS-2$
        hashText.setText(hashValue);
    }

    return hashHexValue;
}

From source file:xyz.jamescarroll.genipass.Crypto.ECKey.java

License:Open Source License

/**
 * Public method that generates the master extended public key.
 *
 * @param u the string of the username/*from  www .j  a  va  2  s.c o m*/
 * @param p the string of the master password.
 * @return an ECKey object representing the master extended public key.
 */

public static ECKey genFromSeeds(String u, String p) {
    RIPEMD160Digest ripemd = new RIPEMD160Digest();
    byte[] digest = new byte[ripemd.getDigestSize()];
    BigInteger hu, hp;

    hu = ripemd160ToBigInteger(u.getBytes(), digest, ripemd);
    hp = ripemd160ToBigInteger(p.getBytes(), digest, ripemd);
    ripemd.reset();

    digest = calcMasterExtPrivateKey(hu, hp);

    return calcExtPublicKey(digest).setmMaster(true);
}

From source file:xyz.jamescarroll.genipass.Crypto.ECKey.java

License:Open Source License

public static byte[] genLoginText(String u, String p) {
    RIPEMD160Digest ripemd = new RIPEMD160Digest();
    Blake2b.Blake2b256 blake = new Blake2b.Blake2b256();
    byte[] digest = new byte[ripemd.getDigestSize()];
    byte[] b = (u + p).getBytes();

    ripemd.update(b, 0, b.length);/*ww w.  j a  v  a  2 s. c o m*/
    ripemd.doFinal(digest, 0);

    for (int i = 0; i < 256; i++) {
        digest = blake.digest(blake.digest(digest));
    }

    return digest;
}