Added import/export to the demo app

- discovered private key length was wrong - fixed
- as things are broken anyway, refactored flyway migrations - you'll need to delete ~/jabit.*.db
This commit is contained in:
2015-07-03 11:28:06 +02:00
parent 65fdd7d408
commit 6f50c200ee
13 changed files with 80 additions and 29 deletions

View File

@ -17,6 +17,7 @@
package ch.dissem.bitmessage.entity.payload;
import ch.dissem.bitmessage.entity.Streamable;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.utils.*;
import org.bouncycastle.crypto.BufferedBlockCipher;
@ -37,6 +38,8 @@ import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import static ch.dissem.bitmessage.entity.valueobject.PrivateKey.PRIVATE_KEY_SIZE;
public class CryptoBox implements Streamable {
private static final Logger LOG = LoggerFactory.getLogger(CryptoBox.class);
@ -59,7 +62,7 @@ public class CryptoBox implements Streamable {
initializationVector = Security.randomBytes(16);
// 3. Generate a new random EC key pair with private key called r and public key called R.
byte[] r = Security.randomBytes(64);
byte[] r = Security.randomBytes(PRIVATE_KEY_SIZE);
R = Security.createPublicKey(r);
// 4. Do an EC point multiply with public key K and private key r. This gives you public key P.
ECPoint P = K.multiply(Security.keyToBigInt(r)).normalize();

View File

@ -32,8 +32,9 @@ import java.io.*;
* Created by chris on 18.04.15.
*/
public class PrivateKey implements Streamable {
private final byte[] privateSigningKey; // 32 bytes
private final byte[] privateEncryptionKey; // 32 bytes
public static final int PRIVATE_KEY_SIZE = 32;
private final byte[] privateSigningKey;
private final byte[] privateEncryptionKey;
private final Pubkey pubkey;
@ -44,8 +45,8 @@ public class PrivateKey implements Streamable {
byte[] pubEK;
byte[] ripe;
do {
privSK = Security.randomBytes(64);
privEK = Security.randomBytes(64);
privSK = Security.randomBytes(PRIVATE_KEY_SIZE);
privEK = Security.randomBytes(PRIVATE_KEY_SIZE);
pubSK = Security.createPublicKey(privSK).getEncoded(false);
pubEK = Security.createPublicKey(privEK).getEncoded(false);
ripe = Pubkey.getRipe(pubSK, pubEK);