|
| 1 | +# What if we want to rotate the encryption keys? |
| 2 | +vault write -force transit/keys/ccid/rotate |
| 3 | + |
| 4 | +# Let's get info about the key now |
| 5 | +vault read transit/keys/ccid |
| 6 | + |
| 7 | +# We can still decrypt data using the old key |
| 8 | +vault write transit/decrypt/ccid ciphertext=$($json_data.data.ciphertext) |
| 9 | + |
| 10 | +# If we try and encrypt a new piece of data, it will use the new key |
| 11 | +$plaintext=[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes("4444123412341234")) |
| 12 | +vault write transit/encrypt/ccid plaintext=$plaintext |
| 13 | + |
| 14 | +# Let's rotate the key a few more times |
| 15 | +vault write -force transit/keys/ccid/rotate |
| 16 | + |
| 17 | +# And we'll set the minimum version availble to 2 |
| 18 | +vault write transit/keys/ccid/config min_decryption_version=2 |
| 19 | + |
| 20 | +# If we try and decrypt our old ciphertext now, we'll get an error |
| 21 | +vault write transit/decrypt/ccid ciphertext=$($json_data.data.ciphertext) |
| 22 | + |
| 23 | +# The key is still there |
| 24 | +vault read transit/keys/ccid |
| 25 | + |
| 26 | +# If we want to purge an older key, we need to set the min encryption version |
| 27 | +# and then we can trim the keys |
| 28 | +vault write transit/keys/ccid/config min_encryption_version=2 |
| 29 | +vault write transit/keys/ccid/trim min_available_version=2 |
| 30 | + |
| 31 | +# Now the key version 1 is gone and you can't get it back |
| 32 | +vault read transit/keys/ccid |
0 commit comments