use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.
the class UtilTest method testGetKeysetInfo.
/**
* Tests that getKeysetInfo doesn't contain key material.
*/
@Test
public void testGetKeysetInfo() throws Exception {
String keyValue = "01234567890123456";
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
assertTrue(keyset.toString().contains(keyValue));
KeysetInfo keysetInfo = Util.getKeysetInfo(keyset);
assertFalse(keysetInfo.toString().contains(keyValue));
}
use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.
the class CreateKeysetCommandTest method testCreateEncrypted_shouldCreateNewKeyset.
private void testCreateEncrypted_shouldCreateNewKeyset(String outFormat) throws Exception {
// Create an encrypted keyset.
String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CreateKeysetCommand.create(outputStream, outFormat, masterKeyUri, credentialPath, KEY_TEMPLATE);
EncryptedKeyset encryptedKeyset = TinkeyUtil.createKeysetReader(new ByteArrayInputStream(outputStream.toByteArray()), outFormat).readEncrypted();
KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(1);
TestUtil.assertKeyInfo(KEY_TEMPLATE, keysetInfo.getKeyInfo(0));
}
use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.
the class AddKeyCommandTest method testAddEncrypted_shouldAddNewKey.
@Test
public void testAddEncrypted_shouldAddNewKey() throws Exception {
// Create an input stream containing an encrypted keyset.
String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
InputStream inputStream = TinkeyUtil.createKeyset(EXISTING_TEMPLATE, INPUT_FORMAT, masterKeyUri, credentialPath);
EncryptedKeyset encryptedKeyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, NEW_TEMPLATE).readEncrypted();
KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(2);
assertThat(keysetInfo.getPrimaryKeyId()).isEqualTo(keysetInfo.getKeyInfo(0).getKeyId());
TestUtil.assertKeyInfo(EXISTING_TEMPLATE, keysetInfo.getKeyInfo(0));
TestUtil.assertKeyInfo(NEW_TEMPLATE, keysetInfo.getKeyInfo(0));
}
use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.
the class ListKeysetCommand method list.
/**
* Lists all keys in the keyset in {@code inputStream} (using {@code credentialPath} to
* decrypt if it is encrypted). This command doesn't output actual key material.
*/
public static void list(InputStream inputStream, String inFormat, String masterKeyUri, String credentialPath) throws Exception {
KeysetHandle handle = TinkeyUtil.getKeysetHandle(inputStream, inFormat, masterKeyUri, credentialPath);
KeysetInfo keysetInfo = handle.getKeysetInfo();
System.out.println(keysetInfo.toString());
}
use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.
the class RotateKeysetCommandTest method testRotateEncrypted_shouldAddNewKey.
@Test
public void testRotateEncrypted_shouldAddNewKey() throws Exception {
// Create an input stream containing an encrypted keyset.
String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
InputStream inputStream = TinkeyUtil.createKeyset(EXISTING_TEMPLATE, INPUT_FORMAT, masterKeyUri, credentialPath);
EncryptedKeyset encryptedKeyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, NEW_TEMPLATE).readEncrypted();
KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(2);
assertThat(keysetInfo.getPrimaryKeyId()).isEqualTo(keysetInfo.getKeyInfo(1).getKeyId());
TestUtil.assertKeyInfo(EXISTING_TEMPLATE, keysetInfo.getKeyInfo(0));
TestUtil.assertKeyInfo(NEW_TEMPLATE, keysetInfo.getKeyInfo(0));
}
Aggregations