use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class HashicorpVaultKeyGeneratorTest method setUp.
@Before
public void setUp() {
this.encryptor = mock(Encryptor.class);
this.keyVaultService = mock(KeyVaultService.class);
final KeyPair keyPair = new KeyPair(pub, priv);
when(encryptor.generateNewKeys()).thenReturn(keyPair);
this.hashicorpVaultKeyGenerator = new HashicorpVaultKeyGenerator(encryptor, keyVaultService);
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class EllipticalCurveEncryptorTest method generateNewKeys.
@Test
public void generateNewKeys() throws Exception {
KeyPair keyPair = encryptor.generateNewKeys();
assertThat(keyPair).isNotNull();
assertThat(keyPair.getPublicKey()).isNotNull();
assertThat(keyPair.getPrivateKey()).isNotNull();
LOGGER.info("Public key size: {}", keyPair.getPublicKey().getKeyBytes().length);
LOGGER.info("Private key size: {}", keyPair.getPrivateKey().getKeyBytes().length);
String b64encodedPrivateKey = Base64.getEncoder().encodeToString(keyPair.getPrivateKey().getKeyBytes());
LOGGER.info("base64 encoded private key: {}", b64encodedPrivateKey);
LOGGER.info("base64 encoded private key length: {}", b64encodedPrivateKey.length());
String b64encodedPublicKey = Base64.getEncoder().encodeToString(keyPair.getPublicKey().getKeyBytes());
LOGGER.info("base64 encoded public key: {}", b64encodedPublicKey);
LOGGER.info("base64 encoded public key length: {}", b64encodedPublicKey.length());
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class EllipticalCurveEncryptorTest method computeSharedKey.
@Test
public void computeSharedKey() {
KeyPair keyPair1 = encryptor.generateNewKeys();
KeyPair keyPair2 = encryptor.generateNewKeys();
SharedKey sharedPub1Priv2 = encryptor.computeSharedKey(keyPair1.getPublicKey(), keyPair2.getPrivateKey());
SharedKey sharedPriv1Pub2 = encryptor.computeSharedKey(keyPair2.getPublicKey(), keyPair1.getPrivateKey());
assertEquals(sharedPub1Priv2, sharedPriv1Pub2);
LOGGER.info("SharedKey: {}", sharedPriv1Pub2.encodeToBase64());
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class AWSSecretManagerKeyGenerator method generate.
@Override
public AWSKeyPair generate(String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) {
final KeyPair keys = this.encryptor.generateNewKeys();
final StringBuilder publicId = new StringBuilder();
final StringBuilder privateId = new StringBuilder();
if (filename != null) {
final Path path = Paths.get(filename);
final String secretId = path.getFileName().toString();
if (!secretId.matches("^[0-9a-zA-Z\\-/_+=.@]*$")) {
throw new UnsupportedCharsetException("Generated key ID for AWS Secret Manager can contain only 0-9, a-z, A-Z and /_+=.@- characters");
}
publicId.append(secretId);
privateId.append(secretId);
}
publicId.append("Pub");
privateId.append("Key");
saveKeyInSecretManager(publicId.toString(), keys.getPublicKey());
saveKeyInSecretManager(privateId.toString(), keys.getPrivateKey());
return new AWSKeyPair(publicId.toString(), privateId.toString());
}
use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.
the class AzureVaultKeyGenerator method generate.
@Override
public AzureVaultKeyPair generate(String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) {
final KeyPair keys = this.nacl.generateNewKeys();
final StringBuilder publicId = new StringBuilder();
final StringBuilder privateId = new StringBuilder();
if (filename != null) {
final Path path = Paths.get(filename);
final String keyVaultId = path.getFileName().toString();
if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) {
throw new UnsupportedCharsetException("Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters");
}
publicId.append(keyVaultId);
privateId.append(keyVaultId);
}
publicId.append("Pub");
privateId.append("Key");
saveKeyInVault(publicId.toString(), keys.getPublicKey());
saveKeyInVault(privateId.toString(), keys.getPrivateKey());
return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null);
}
Aggregations