static public PrivateKey privateKey(int index) throws EncryptionError { byte[] src = Do.decodeBase64(binaryKeys[index]); return new PrivateKey(src); }
static PrivateKey privateKey(int index) { byte[] src = Do.decodeBase64(binaryKeys[index]); try { return new PrivateKey(src); } catch (EncryptionError encryptionError) { throw new RuntimeException("failed to create test key", encryptionError); } }
static public PrivateKey privateKey(int index) throws EncryptionError { byte[] src = Do.decodeBase64(binaryKeys[index]); return new PrivateKey(src); }
static public PrivateKey privateKey(int index) throws EncryptionError { byte[] src = Do.decodeBase64(binaryKeys[index]); return new PrivateKey(src); }
@Test public void computeSha512() { String src = "test $pbkdf$pbkdf2-sha512$5000$26$KFuMDXmo$yPsu5qmQto99vDqAMWnldNuagfVl5OhPr6g="; String[] parts = src.split("\\$"); String password = parts[0].trim(); int c = Integer.valueOf(parts[3]); int dkLen = Integer.valueOf(parts[4]); byte[] salt = Do.decodeBase64(parts[5]); //.getBytes(); byte[] DK = Do.decodeBase64(parts[6]); assertArrayEquals(DK, PBKDF2.derive(Sha512.class, password, salt, c, dkLen)); }
@Test public void serializationTest() throws Exception { byte[] packedPublicKey = Do.decodeBase64(publicKey64); PublicKey publicKey = new PublicKey(packedPublicKey); byte[] packedPublicKey2 = publicKey.pack(); assertArrayEquals(packedPublicKey, packedPublicKey2); byte[] packedPrivateKey = Do.decodeBase64(TestKeys.binaryKeys[3]); PrivateKey privateKey = new PrivateKey(packedPrivateKey); byte[] packedPrivateKey2 = privateKey.pack(); assertArrayEquals(packedPrivateKey, packedPrivateKey2); }
@Test public void testKeys() throws Exception { // Test vectors are for key #1 PrivateKey key = (PrivateKey) TestKeys.privateKey(1); byte[] encrypted = Bytes.fromBase64(encrypted64).toArray(); byte[] decrypted = key.decrypt(encrypted); assertEquals(plainText, new String(decrypted)); PublicKey publicKey = key.getPublicKey(); byte[] encrypted2 = publicKey.encrypt(plainText); assertEquals(plainText, new String(key.decrypt(encrypted2))); publicKey = new PublicKey(Do.decodeBase64(publicKey64)); encrypted2 = publicKey.encrypt(plainText); assertEquals(plainText, new String(key.decrypt(encrypted2))); }
@Test public void signatureTest() throws Exception { PrivateKey privateKey = TestKeys.privateKey(1); PublicKey publicKey = privateKey.getPublicKey(); byte [] signature256 = Do.decodeBase64(signature256_64); final byte[] signature512 = Do.decodeBase64(signature512_64); assertTrue(publicKey.verify(plainText, signature256, HashType.SHA256)); assertFalse(publicKey.verify(plainText+"tampered", signature256, HashType.SHA256)); assertFalse(publicKey.verify(plainText, signature256, HashType.SHA512)); assertTrue(publicKey.verify(plainText, signature512, HashType.SHA512)); assertFalse(publicKey.verify(plainText, signature512, HashType.SHA256)); assertFalse(publicKey.verify(plainText+"tampered", signature512, HashType.SHA512)); }