Я новичок в Cloud KMS, и я начал точно следовать тому, что написано здесь
Я зашифровал свой файл данных, сохраненный в формате UTF-8, выполнив эту команду
gcloud kms encrypt --location global --keyring ring --key key --plaintext-file /path_to_file --ciphertext-file /path_to_enc --project myProject
затем в результате мои зашифрованные данные были представлены в этом формате в моем новом созданном зашифрованном файле
$�]ˋLݿ���yHI�lS�`&�Nt�b{%�U�� �&�A���XaL��d
вот как я читаю данные зашифрованного файла:
static Properties properties = new Properties();
static {
try {
InputStream in = new Credentials().getClass().getResourceAsStream("path_to_enc_file");
byte[] encryptedData = IOUtils.toByteArray(in);
byte[] decryptedBytes = decrypt(EnvironmentVariable.getProjectId(), "global", "ring", "key", encryptedData);
ByteArrayInputStream bis = new ByteArrayInputStream(decryptedBytes);
properties.load(bis);
in.close();
bis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
и теперь всякий раз, когда я пытаюсь расшифровать его с помощью этой функции:
public static byte[] decrypt(
String projectId, String locationId, String keyRingId, String cryptoKeyId, byte[] ciphertext)
throws IOException {
// Create the KeyManagementServiceClient using try-with-resources to manage client cleanup.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// The resource name of the cryptoKey
String resourceName = CryptoKeyName.format(projectId, locationId, keyRingId, cryptoKeyId);
// Decrypt the ciphertext with Cloud KMS.
DecryptResponse response = client.decrypt(resourceName, ByteString.copyFrom(ciphertext));
// Extract the plaintext from the response.
return response.getPlaintext().toByteArray();
}
}
он выбрасывает
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Decryption failed: the ciphertext is invalid.",
"reason" : "badRequest"
} ],
"message" : "Decryption failed: the ciphertext is invalid.",
"status" : "INVALID_ARGUMENT"
}
тип ключа: Symmetric encrypt/decrypt
Алгоритм по умолчанию: Google symmetric key
расположение кольца: global
Можете ли вы помочь мне и скажите, что отсутствует в Google Docs?