public static String getFingerprint(Contact contact, String localeCode) throws GeneralSecurityException { String[] wordList = I2PBote.getInstance().getWordList(localeCode); Fingerprint fingerprint = contact.getFingerprint(); return fingerprint==null ? null : fingerprint.getWords(wordList); }
@Test public void testSignatureAndFingerprint() throws GeneralSecurityException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { assertTrue(contact.verify()); // change the name char[] chars = contactName.toCharArray(); chars[0]++; String alteredName = new String(chars); contact.setName(alteredName); assertFalse(contact.verify()); // restore the original name and make the salt invalid contact.setName(contactName); Fingerprint fingerprint = contact.getFingerprint(); Field saltField = Fingerprint.class.getDeclaredField("salt"); saltField.setAccessible(true); byte[] salt = (byte[])saltField.get(fingerprint); salt[2]++; assertFalse(contact.verify()); // restore salt salt[2]--; assertTrue(contact.verify()); } }
@Test public void toByteArrayAndBack() throws IOException, GeneralSecurityException { WordListAnchor wordLists = new WordListAnchor(); String[] wordListEN = wordLists.getWordList("en"); String[] wordListDE = wordLists.getWordList("de"); byte[] arrayA = contact.toByteArray(); Contact contact2 = new Contact(arrayA); assertEquals(contact.getName(), contact2.getName()); assertEquals(contact.getDestination().toBase64(), contact2.getDestination().toBase64()); assertEquals(contact.getText(), contact2.getText()); assertEquals(contact.getFingerprint().getWords(wordListDE), contact2.getFingerprint().getWords(wordListDE)); assertEquals(contact.getFingerprint().getWords(wordListEN), contact2.getFingerprint().getWords(wordListEN)); assertFalse(contact.getFingerprint().getWords(wordListEN).equals(contact2.getFingerprint().getWords(wordListDE))); assertEquals(contact.getPictureBase64(), contact2.getPictureBase64()); byte[] arrayB = contact2.toByteArray(); assertArrayEquals("The two arrays differ!", arrayA, arrayB); }