net.bither.bitherj.crypto.bip38.Bip38 Java Examples

The following examples show how to use net.bither.bitherj.crypto.bip38.Bip38. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialogImportBip38KeyText.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    if (v.getId() == R.id.btn_ok) {
        String s = et.getText().toString();
        if (Utils.isEmpty(s)) {
            tvError.setVisibility(View.VISIBLE);
            shake();
            return;
        }
        try {
            if (!Bip38.isBip38PrivateKey(s)) {
                tvError.setVisibility(View.VISIBLE);
                shake();
                return;
            }
            bip38KeyString = et.getText().toString();
            dismiss();

        } catch (AddressFormatException e) {
            tvError.setVisibility(View.VISIBLE);
            e.printStackTrace();
        }
    } else {
        dismiss();
    }
}
 
Example #2
Source File: DialogImportBip38KeyText.java    From bither-android with Apache License 2.0 6 votes vote down vote up
private void showBip38Password() {
    DialogPasswordWithOther d = new DialogPasswordWithOther(getContext(), bip38IDialogPasswordListener);
    d.setCheckPre(false);
    d.setTitle(R.string.enter_bip38_key_password);
    d.setCheckPasswordListener(new ICheckPasswordListener() {
        @Override
        public boolean checkPassword(SecureCharSequence password) {
            try {
                decode = Bip38.decrypt(bip38KeyString, password).toString();
                return decode != null;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
    });
    d.show();
}
 
Example #3
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public static String getBIP38PrivateKeyString(Address address, CharSequence password) throws
        AddressFormatException, InterruptedException {
    SecureCharSequence decrypted = getDecryptPrivateKeyString(address.getFullEncryptPrivKey()
            , password);
    String bip38 = Bip38.encryptNoEcMultiply(password, decrypted.toString());
    if (BitherjSettings.DEV_DEBUG) {
        SecureCharSequence d = Bip38.decrypt(bip38, password);
        if (d.equals(decrypted)) {
            log.info("BIP38 right");
        } else {
            throw new RuntimeException("BIP38 wrong " + d.toString() + " , " +
                    "" + decrypted.toString());
        }
    }
    decrypted.wipe();
    return bip38;
}
 
Example #4
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }
    ImportPrivateKeyDesktop importPrivateKey = new ImportPrivateKeyDesktop(
            ImportPrivateKey.ImportPrivateKeyType.Bip38, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #5
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    if (password == null) {
        return;
    }
    ImportPrivateKeyDesktop importPrivateKey = new ImportPrivateKeyDesktop(
            ImportPrivateKey.ImportPrivateKeyType.Bip38, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #6
Source File: Bip38Test.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyWithLot2WithBom() throws InterruptedException, UnsupportedEncodingException, AddressFormatException {
    // "MOLON LABE" using greek characters  = "ΜΟΛΩΝ ΛΑΒΕ"
    String passphrase = "\u039C\u039F\u039B\u03A9\u039D \u039B\u0391\u0392\u0395";
    assertEquals("ce9cce9fce9bcea9ce9d20ce9bce91ce92ce95".toUpperCase(), Utils.bytesToHexString(passphrase.getBytes("UTF-8")));
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PgGWtx25kUg8QWvwuJAgorN6k9FbE25rv5dMRwu5SKMnfpfVe5mar2ngH", passphrase);
    assertEquals(decoded.toString(), "5KMKKuUmAkiNbA3DazMQiLfDq47qs8MAEThm4yL8R2PhV1ov33D");
}
 
Example #7
Source File: Bip38Test.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyWithLot2() throws InterruptedException, UnsupportedEncodingException, AddressFormatException {
    // "MOLON LABE" using greek characters  = "ΜΟΛΩΝ ΛΑΒΕ"
    String passphrase = "\u039C\u039F\u039B\u03A9\u039D \u039B\u0391\u0392\u0395";
    assertEquals("ce9cce9fce9bcea9ce9d20ce9bce91ce92ce95".toUpperCase(), Utils.bytesToHexString(passphrase.getBytes("UTF-8")));
    SecureCharSequence decoded = Bip38.decrypt("6PgGWtx25kUg8QWvwuJAgorN6k9FbE25rv5dMRwu5SKMnfpfVe5mar2ngH", passphrase);
    assertEquals(decoded.toString(), "5KMKKuUmAkiNbA3DazMQiLfDq47qs8MAEThm4yL8R2PhV1ov33D");
}
 
Example #8
Source File: Bip38Test.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptCompression2() throws InterruptedException, AddressFormatException {
    String encoded = Bip38.encryptNoEcMultiply("Satoshi", "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7"
    );
    assertEquals(encoded, "6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7");
    assertTrue(Bip38.isBip38PrivateKey(encoded));
}
 
Example #9
Source File: Bip38Test.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptCompression1() throws InterruptedException, AddressFormatException {
    String encoded = Bip38.encryptNoEcMultiply("TestingOneTwoThree",
            "L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP");
    assertEquals(encoded, "6PYNKZ1EAgYgmQfmNVamxyXVWHzK5s6DGhwP4J5o44cvXdoY7sRzhtpUeo");
    assertTrue(Bip38.isBip38PrivateKey(encoded));
}
 
Example #10
Source File: Bip38Test.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncryptNoCompression() throws InterruptedException, AddressFormatException {
    String encoded = Bip38.encryptNoEcMultiply("TestingOneTwoThree",
            "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR");
    assertEquals(encoded, "6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg");
    assertTrue(Bip38.isBip38PrivateKey(encoded));
}
 
Example #11
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyNoLot1WithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2");
}
 
Example #12
Source File: ImportBIP38PrivateTextDialog.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    ImportPrivateKeyDesktop importPrivateKey = new ImportPrivateKeyDesktop(
            ImportPrivateKey.ImportPrivateKeyType.Bip38, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #13
Source File: ImportBIP38PrivateTextDialog.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    ImportPrivateKeyDesktop importPrivateKey = new ImportPrivateKeyDesktop(
            ImportPrivateKey.ImportPrivateKeyType.Bip38, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #14
Source File: DialogImportBip38KeyText.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    ImportPrivateKeyAndroid importPrivateKey = new ImportPrivateKeyAndroid(activity,
            ImportPrivateKey.ImportPrivateKeyType.Bip38, pd, decode, password);
    importPrivateKey.importPrivateKey();
}
 
Example #15
Source File: ColdAdvanceActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    ImportPrivateKeyAndroid importPrivateKey = new ImportPrivateKeyAndroid(ColdAdvanceActivity.this,
            ImportPrivateKey.ImportPrivateKeyType.Bip38, dp, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #16
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyWithLot1WithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PgNBNNzDkKdhkT6uJntUXwwzQV8Rr2tZcbkDcuC9DZRsS6AtHts4Ypo1j", "MOLON LABE");
    assertEquals(decoded.toString(), "5JLdxTtcTHcfYcmJsNVy1v2PMDx432JPoYcBTVVRHpPaxUrdtf8");
}
 
Example #17
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyWithLot1() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PgNBNNzDkKdhkT6uJntUXwwzQV8Rr2tZcbkDcuC9DZRsS6AtHts4Ypo1j", "MOLON LABE");
    assertEquals(decoded.toString(), "5JLdxTtcTHcfYcmJsNVy1v2PMDx432JPoYcBTVVRHpPaxUrdtf8");
}
 
Example #18
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyNoLot2WithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PfLGnQs6VZnrNpmVKfjotbnQuaJK4KZoPFrAjx1JMJUa1Ft8gnf5WxfKd", "Satoshi");
    assertEquals(decoded.toString(), "5KJ51SgxWaAYR13zd9ReMhJpwrcX47xTJh2D3fGPG9CM8vkv5sH");
}
 
Example #19
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyNoLot2() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PfLGnQs6VZnrNpmVKfjotbnQuaJK4KZoPFrAjx1JMJUa1Ft8gnf5WxfKd", "Satoshi");
    assertEquals(decoded.toString(), "5KJ51SgxWaAYR13zd9ReMhJpwrcX47xTJh2D3fGPG9CM8vkv5sH");
}
 
Example #20
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompression() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR");
}
 
Example #21
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithEcMultiplyNoLot1() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PfQu77ygVyJLZjfvMLyhLMQbYnu5uguoJJ4kMCLqWwPEdfpwANVS76gTX",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "5K4caxezwjGCGfnoPTZ8tMcJBLB7Jvyjv4xxeacadhq8nLisLR2");
}
 
Example #22
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptCompression2WithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7", "Satoshi");
    assertEquals(decoded.toString(), "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7");
}
 
Example #23
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptCompression2() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PYLtMnXvfG3oJde97zRyLYFZCYizPU5T3LwgdYJz1fRhh16bU7u6PPmY7", "Satoshi");
    assertEquals(decoded.toString(), "KwYgW8gcxj1JWJXhPSu4Fqwzfhp5Yfi42mdYmMa4XqK7NJxXUSK7");
}
 
Example #24
Source File: HotAdvanceActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPasswordEntered(SecureCharSequence password) {
    ImportPrivateKeyAndroid importPrivateKey = new ImportPrivateKeyAndroid(HotAdvanceActivity.this,
            ImportPrivateKey.ImportPrivateKeyType.Bip38, dp, bip38DecodeString, password);
    importPrivateKey.importPrivateKey();
}
 
Example #25
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptCompression1WithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PYNKZ1EAgYgmQfmNVamxyXVWHzK5s6DGhwP4J5o44cvXdoY7sRzhtpUeo",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP");
}
 
Example #26
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptCompression1() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("6PYNKZ1EAgYgmQfmNVamxyXVWHzK5s6DGhwP4J5o44cvXdoY7sRzhtpUeo",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "L44B5gGEpqEDRS9vVPz7QT35jcBG2r3CZwSwQ4fCewXAhAhqGVpP");
}
 
Example #27
Source File: Bip38Test.java    From bitherj with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecryptNoCompressionWithBom() throws InterruptedException, AddressFormatException {
    SecureCharSequence decoded = Bip38.decrypt("\uFEFF6PRVWUbkzzsbcVac2qwfssoUJAN1Xhrg6bNk8J7Nzm5H7kxEbn2Nh2ZoGg",
            "TestingOneTwoThree");
    assertEquals(decoded.toString(), "5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR");
}