Search in sources :

Example 1 with Pbkdf2Param

use of tech.pegasys.signers.bls.keystore.model.Pbkdf2Param in project signers by ConsenSys.

the class KeyStoreTest method encryptUsingPBKDF2AndSaveKeyStore.

@Test
void encryptUsingPBKDF2AndSaveKeyStore(@TempDir final Path tempDir) throws IOException {
    final KdfParam kdfParam = new Pbkdf2Param(DKLEN, ITERATIVE_COUNT, Pbkdf2PseudoRandomFunction.HMAC_SHA256, SALT);
    encryptSaveAndReloadKeyStore(tempDir, kdfParam);
}
Also used : KdfParam(tech.pegasys.signers.bls.keystore.model.KdfParam) Pbkdf2Param(tech.pegasys.signers.bls.keystore.model.Pbkdf2Param) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Pbkdf2Param

use of tech.pegasys.signers.bls.keystore.model.Pbkdf2Param in project signers by ConsenSys.

the class DecryptionKeyTest method pbkdf2DecryptionKeyGeneration.

@Test
void pbkdf2DecryptionKeyGeneration() {
    final Pbkdf2Param kdfParam = new Pbkdf2Param(DKLEN, ITERATIVE_COUNT, Pbkdf2PseudoRandomFunction.HMAC_SHA256, SALT);
    final Bytes decryptionKey = kdfParam.generateDecryptionKey(PASSWORD);
    assertThat(decryptionKey.size()).isEqualTo(DKLEN);
    assertThat(decryptionKey).isEqualTo(PBKDF2_DERIVED_KEY);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Pbkdf2Param(tech.pegasys.signers.bls.keystore.model.Pbkdf2Param) Test(org.junit.jupiter.api.Test)

Example 3 with Pbkdf2Param

use of tech.pegasys.signers.bls.keystore.model.Pbkdf2Param in project web3signer by ConsenSys.

the class MetadataFileHelpers method createKeyStoreFile.

private void createKeyStoreFile(final Path keyStoreFilePath, final String password, final Bytes privateKey, final Bytes publicKey, final KdfFunction kdfFunctionType) {
    final KdfParam kdfParam = kdfFunctionType == KdfFunction.SCRYPT ? new SCryptParam(32, SALT) : new Pbkdf2Param(32, 262144, HMAC_SHA256, SALT);
    final Cipher cipher = new Cipher(CipherFunction.AES_128_CTR, IV);
    final KeyStoreData keyStoreData = KeyStore.encrypt(privateKey, publicKey, password, "m/12381/3600/0/0/0", kdfParam, cipher);
    try {
        KeyStoreLoader.saveToFile(keyStoreFilePath, keyStoreData);
    } catch (IOException e) {
        fail("Unable to create keystore file", e);
    }
}
Also used : SCryptParam(tech.pegasys.signers.bls.keystore.model.SCryptParam) KdfParam(tech.pegasys.signers.bls.keystore.model.KdfParam) Cipher(tech.pegasys.signers.bls.keystore.model.Cipher) IOException(java.io.IOException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) Pbkdf2Param(tech.pegasys.signers.bls.keystore.model.Pbkdf2Param)

Example 4 with Pbkdf2Param

use of tech.pegasys.signers.bls.keystore.model.Pbkdf2Param in project web3signer by ConsenSys.

the class KeystoreUtil method createKeystoreFile.

public static void createKeystoreFile(final BLSKeyPair keyPair, final Path keystoreDir, final String password) {
    final KdfParam kdfParam = new Pbkdf2Param(32, 2, HMAC_SHA256, SALT);
    final Cipher cipher = new Cipher(CipherFunction.AES_128_CTR, IV);
    final Bytes48 publicKey = keyPair.getPublicKey().toBytesCompressed();
    final KeyStoreData keyStoreData = KeyStore.encrypt(keyPair.getSecretKey().toBytes(), publicKey, password, "", kdfParam, cipher);
    try {
        KeyStoreLoader.saveToFile(keystoreDir.resolve(publicKey + ".json"), keyStoreData);
        publicKey.toHexString();
    } catch (IOException e) {
        throw new IllegalStateException("Unable to create keystore file", e);
    }
}
Also used : Bytes48(org.apache.tuweni.bytes.Bytes48) KdfParam(tech.pegasys.signers.bls.keystore.model.KdfParam) Cipher(tech.pegasys.signers.bls.keystore.model.Cipher) IOException(java.io.IOException) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) Pbkdf2Param(tech.pegasys.signers.bls.keystore.model.Pbkdf2Param)

Example 5 with Pbkdf2Param

use of tech.pegasys.signers.bls.keystore.model.Pbkdf2Param in project web3signer by ConsenSys.

the class FileValidatorManagerTest method createKeystoreString.

private String createKeystoreString() throws JsonProcessingException {
    final Cipher cipher = new Cipher(CipherFunction.AES_128_CTR, IV);
    final Pbkdf2Param pbkdf2Param = new Pbkdf2Param(32, 262144, HMAC_SHA256, SALT);
    final KeyStoreData keyStoreData = KeyStore.encrypt(BLS_KEY_PAIR.getSecretKey().toBytes(), BLS_KEY_PAIR.getPublicKey().toBytesCompressed(), "password", "", pbkdf2Param, cipher);
    return OBJECT_MAPPER.writeValueAsString(keyStoreData);
}
Also used : Cipher(tech.pegasys.signers.bls.keystore.model.Cipher) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) Pbkdf2Param(tech.pegasys.signers.bls.keystore.model.Pbkdf2Param)

Aggregations

Pbkdf2Param (tech.pegasys.signers.bls.keystore.model.Pbkdf2Param)7 Cipher (tech.pegasys.signers.bls.keystore.model.Cipher)5 KdfParam (tech.pegasys.signers.bls.keystore.model.KdfParam)5 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)3 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes48 (org.apache.tuweni.bytes.Bytes48)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 SCryptParam (tech.pegasys.signers.bls.keystore.model.SCryptParam)1