Permalink
Browse files

added round-trip test

  • Loading branch information...
1 parent 0a9b2db commit fd35cc7d7e73008800af24f6d6700d43cb5521f0 @dbasch committed Jan 18, 2014
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/test/java/com/fruitcat/bitcoin/BIP38Test.java
@@ -2,30 +2,43 @@
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
+import java.util.Random;
/**
* Unit tests
*
*/
public class BIP38Test {
+ String testPass = "TestingOneTwoThree";
+
//EC multiply, no compression, no lot/sequence numbers
@Test
public void decryptECNoCompressionNoLotTest() throws Exception {
String encryptedKey = "6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX";
- String pass = "TestingOneTwoThree";
String key = "5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2";
- String decryptedKey = BIP38.decrypt(pass, encryptedKey);
+ String decryptedKey = BIP38.decrypt(testPass, encryptedKey);
assertEquals(key, decryptedKey);
}
@Test
public void decryptNoECNoCompression() throws Exception {
String encryptedKey = "6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg";
- String pass = "TestingOneTwoThree";
String key = "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR";
- String decryptedKey = BIP38.decrypt(pass, encryptedKey);
+ String decryptedKey = BIP38.decrypt(testPass, encryptedKey);
assertEquals(key, decryptedKey);
}
+
+ //round encrypt and decrypt with a random ascii password
+ @Test
+ public void randomRoundTripNoEC() throws Exception {
+ byte[] r = new byte[16];
+ (new Random()).nextBytes(r);
+ String randomPass = new String(r, "ASCII");
+ System.out.println(randomPass);
+ String key = "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR";
+ String encryptedKey = BIP38.encryptNoEC(key, randomPass, false);
+ assertEquals(key, (BIP38.decrypt(randomPass, encryptedKey)));
+ }
}

0 comments on commit fd35cc7

Please sign in to comment.