Search in sources :

Example 1 with Cipher

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

the class KeyStore method encryptUsingCipherFunction.

private static Crypto encryptUsingCipherFunction(final Bytes secret, final String password, final KdfParam kdfParam, final Cipher cipher) {
    final Bytes decryptionKey = kdfParam.generateDecryptionKey(password);
    final Bytes cipherMessage = applyCipherFunction(decryptionKey, cipher, true, secret.toArrayUnsafe());
    final Bytes checksumMessage = calculateSHA256Checksum(decryptionKey, cipherMessage);
    final Checksum checksum = new Checksum(checksumMessage);
    final Cipher encryptedCipher = new Cipher(cipher.getCipherFunction(), cipher.getCipherParam(), cipherMessage);
    final Kdf kdf = new Kdf(kdfParam);
    return new Crypto(kdf, checksum, encryptedCipher);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Crypto(tech.pegasys.signers.bls.keystore.model.Crypto) Checksum(tech.pegasys.signers.bls.keystore.model.Checksum) Cipher(tech.pegasys.signers.bls.keystore.model.Cipher) Kdf(tech.pegasys.signers.bls.keystore.model.Kdf)

Example 2 with Cipher

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

the class BlsArtifactSignerFactoryTest method createKeyStoreFile.

private static void createKeyStoreFile(final Path keyStoreFilePath, final String password, final Bytes privateKey, final Bytes publicKey) {
    final KdfParam kdfParam = new SCryptParam(32, KEYSTORE_SALT);
    final Cipher cipher = new Cipher(CipherFunction.AES_128_CTR, Bytes.fromHexString("e0f20a27d160f7cc92764579390e881a"));
    final KeyStoreData keyStoreData = KeyStore.encrypt(privateKey, publicKey, password, "", 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)

Example 3 with Cipher

use of tech.pegasys.signers.bls.keystore.model.Cipher 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 Cipher

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

the class BlsArtifactSignerFactoryTest method createKeyStoreFile.

private static void createKeyStoreFile(final Path keyStoreFilePath, final String password, final Bytes privateKey, final Bytes publicKey) {
    final KdfParam kdfParam = new SCryptParam(32, KEYSTORE_SALT);
    final Cipher cipher = new Cipher(CipherFunction.AES_128_CTR, Bytes.fromHexString("e0f20a27d160f7cc92764579390e881a"));
    final KeyStoreData keyStoreData = KeyStore.encrypt(privateKey, publicKey, password, "", 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)

Example 5 with Cipher

use of tech.pegasys.signers.bls.keystore.model.Cipher 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)

Aggregations

Cipher (tech.pegasys.signers.bls.keystore.model.Cipher)9 KdfParam (tech.pegasys.signers.bls.keystore.model.KdfParam)6 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)5 Pbkdf2Param (tech.pegasys.signers.bls.keystore.model.Pbkdf2Param)5 IOException (java.io.IOException)4 SCryptParam (tech.pegasys.signers.bls.keystore.model.SCryptParam)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes48 (org.apache.tuweni.bytes.Bytes48)1 Checksum (tech.pegasys.signers.bls.keystore.model.Checksum)1 Crypto (tech.pegasys.signers.bls.keystore.model.Crypto)1 Kdf (tech.pegasys.signers.bls.keystore.model.Kdf)1