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);
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations