Search in sources :

Example 1 with Crypto

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

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

the class KeyStore method encrypt.

/**
 * Encrypt the given BLS12-381 key with specified password.
 *
 * @param blsPrivateKey BLS12-381 private key in Bytes to encrypt. It is not validated to be a
 *     valid BLS12-381 key.
 * @param blsPublicKey BLS12-381 public key in Bytes. It is not validated and stored as it is.
 * @param password The password to use for encryption
 * @param path Path as defined in EIP-2334. Can be empty String.
 * @param kdfParam crypto function such as scrypt or PBKDF2 and related parameters such as dklen,
 *     salt etc.
 * @param cipher cipher function and iv parameter to use.
 * @return The constructed KeyStore with encrypted BLS Private Key as cipher.message and other
 *     details as defined by the EIP-2335 standard.
 */
public static KeyStoreData encrypt(final Bytes blsPrivateKey, final Bytes blsPublicKey, final String password, final String path, final KdfParam kdfParam, final Cipher cipher) {
    checkNotNull(blsPrivateKey, "PrivateKey cannot be null");
    checkNotNull(blsPublicKey, "PublicKey cannot be null");
    checkNotNull(password, "Password cannot be null");
    checkNotNull(path, "Path cannot be null");
    checkNotNull(kdfParam, "KDFParam cannot be null");
    checkNotNull(cipher, "Cipher cannot be null");
    kdfParam.validate();
    cipher.validate();
    final Crypto crypto = encryptUsingCipherFunction(blsPrivateKey, password, kdfParam, cipher);
    return new KeyStoreData(crypto, blsPublicKey, path);
}
Also used : Crypto(tech.pegasys.signers.bls.keystore.model.Crypto) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData)

Aggregations

Crypto (tech.pegasys.signers.bls.keystore.model.Crypto)2 Bytes (org.apache.tuweni.bytes.Bytes)1 Checksum (tech.pegasys.signers.bls.keystore.model.Checksum)1 Cipher (tech.pegasys.signers.bls.keystore.model.Cipher)1 Kdf (tech.pegasys.signers.bls.keystore.model.Kdf)1 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)1