// // ONE TIME ADD CONTACTS // // private static void oneTimeAddContacts() { String firstNameLastName = ""; String saltS = ""; String ssnhash = ""; Set<String> unionSet = new HashSet<>(); unionSet.addAll(set1); unionSet.addAll(set2); String strArrr[] = unionSet.toArray(new String[unionSet.size()]); int numEntries = saltHashMap.size(); for (int i = 0; i < numEntries; i++) { firstNameLastName = strArrr[i]; saltS = saltHashMap.get(strArrr[i]); ssnhash = hashedssnHashMap.get(strArrr[i]); Map<String, AttributeValue> item = newContactItem(firstNameLastName, saltS, ssnhash); PutItemRequest putItemRequest = new PutItemRequest("contacts-table", item); PutItemResult putItemResult = dynamoDB.putItem(putItemRequest); } }
// // ONE TIME ADD WARRANTS // // private static void oneTimeAddWarrants() { String jsonString = ""; try { 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(); } }