diff --git a/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java index a614225..ac10cef 100644 --- a/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/objects/MemoTest.java @@ -57,6 +57,14 @@ public class MemoTest { destinationAddress = new Address(publicKey.getKey()); } + @Test + public void canObtainSharedSecret(){ + byte[] secret1 = sourcePrivate.getPubKeyPoint().multiply(destinationPrivate.getPrivKey()).normalize().getXCoord().getEncoded(); + byte[] secret2 = destinationPrivate.getPubKeyPoint().multiply(sourcePrivate.getPrivKey()).normalize().getXCoord().getEncoded(); + System.out.println(String.format("Secret 1: %s, Secret 2: %s", Util.bytesToHex(secret1), Util.bytesToHex(secret2))); + Assert.assertArrayEquals(secret1, secret2); + } + @Test public void shouldMatchPredefinedCiphertext(){ byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, shortEncryptedMessageNonce, shortMessage); @@ -118,6 +126,19 @@ public class MemoTest { } } + @Test + public void shouldDecryptOwnMessage(){ + try{ + BigInteger nonce = new BigInteger("123456789"); + byte[] encrypted = Memo.encryptMessage(sourcePrivate, destinationAddress, nonce, longerMessage); + String decrypted = Memo.decryptMessage(sourcePrivate, destinationAddress, nonce, encrypted); + System.out.println("Decrypted: "+decrypted); + Assert.assertEquals(longerMessage, decrypted); + }catch (ChecksumException e) { + e.printStackTrace(); + } + } + @Test(expected = ChecksumException.class) public void shouldThrowException() throws ChecksumException { byte[] corrupted = Memo.encryptMessage(sourcePrivate, destinationAddress, longEncryptedMessageNonce, longerMessage);