Base64 encoding and decoding

Key Management Service takes as input, and returns as output, content that has been encoded using base64 encoding.

For example, base64-encoding the following quote (without the quote marks)

"You can observe a lot by watching. --Yogi Berra"

results in this base64-encoded value:

WW91IGNhbiBvYnNlcnZlIGEgbG90IGJ5IHdhdGNoaW5nLiAtLVlvZ2kgQmVycmEK

Encoding content as base64

To base64-encode a file and store the contents in a new file:

Linux

Encode the file using the base64 command-line tool, making sure to prevent line-wrapping by using the -w 0 flag:

base64 [SOURCE_FILE] -w 0 > [ENCODED_FILE]

Mac OSX

Encode the file using the base64 command-line tool:

base64 [SOURCE_FILE] > [ENCODED_FILE]

Windows

Encode the file using the certutil command-line tool with the -encode option.

Because certutil places ---BEGIN CERTIFICATE and ---END CERTIFICATE delimiters around the encoded content, use a temporary file and the findstr command to produce an encoded file without the CERTIFICATE delimiters. Remember to delete the temporary file, as shown in this example.

certutil -encode [SOURCE_FILE] tempfile.tmp
findstr /v /c:CERTIFICATE tempfile.tmp > [ENCODED_FILE]
del tempfile.tmp

When you use the KMS API to make your call, include the base64-encoded content in your JSON request. For example, when calling the encrypt method:

{
  "plaintext": "U3VwZXIgc2VjcmV0IHRleHQgdGhhdCBtdXN0IGJlIGVuY3J5cHRlZAo=",
}

Decoding base64-encoded content

To decode a base64-encoded file and store the contents in a new file:

Linux

Decode the file using the base64 command-line tool with the --decode option:

base64 --decode [ENCODED_FILE] > [DECODED_FILE]

Mac OSX

Decode the file using the base64 command-line tool with the --decode option:

base64 --decode [ENCODED_FILE] > [DECODED_FILE]

Windows

Decode the file using the certutil command-line tool with the -decode option:

certutil -decode [ENCODED_FILE] [DECODED_FILE]
Bu sayfayı yararlı buldunuz mu? Lütfen görüşünüzü bildirin:

Şunun hakkında geri bildirim gönderin...

Cloud KMS Documentation