add generatePairingKey
This commit is contained in:
parent
93162a4c1e
commit
746ac5c8f0
|
@ -1,16 +1,22 @@
|
|||
package im.status.applet_installer_test.appletinstaller;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
|
||||
|
@ -125,4 +131,13 @@ public class Crypto {
|
|||
throw new RuntimeException("error generating ICV.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] generatePairingKey(char[] pairing) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
|
||||
String salt = "Status Hardware Wallet Lite";
|
||||
PBEKeySpec spec = new PBEKeySpec(pairing, salt.getBytes(), 50000, 32*8);
|
||||
SecretKey key = skf.generateSecret(spec);
|
||||
|
||||
return key.getEncoded();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package im.status.applet_installer_test.appletinstaller;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import im.status.applet_installer_test.appletinstaller.apducommands.InitializeUpdate;
|
||||
|
@ -50,4 +55,12 @@ public class CryptoTest {
|
|||
byte[] result = Crypto.macFull3des(key, data, Crypto.NullBytes8);
|
||||
assertEquals(expected, HexUtils.byteArrayToHexString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePairingKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
String pairing = "zoynhcfz1xJjYqxO";
|
||||
byte[] key = Crypto.generatePairingKey(pairing.toCharArray());
|
||||
String expected = "BF8D606E2FE9292B633DF5E31563AF88928EEBB71FDBCBEF6CADECAA00D7874F";
|
||||
assertEquals(expected, HexUtils.byteArrayToHexString(key));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue