Shawn Willden edited this page Mar 7, 2015 · 1 revision

Decrypting with Keyczar

Decrypt data formatted as CiphertextFormat and possibly encoded as WebSafeBase64.


Java will either decode the ciphertext as a WebSafeBase64 if input as a java string or will not do any decoding if passed in as a byte string. A byte string will be returned if a byte string is input and a java string will be output if a java string is input.

Crypter crypter = new Crypter("/path/to/your/keys");
String ciphertext = crypter.encrypt("Secret message");
String plaintext = crypter.decrypt(ciphertext);


Python will only take strings of bytes as input. It expects it to be encoded in WebSafeBase64, but this can be changed by setting the decoder. It will return the plaintext as a python string.

crypter = Crypter.Read("/path/to/your/keys")
ciphertext = crypter.Encrypt("Secret message")
plaintext = crypter.Decrypt(ciphertext)


C++ expects a WebSafeBase64 encoded ciphertext string by default. The type of encoding can be modified through the set_encoding method on the crypter to take a byte string. It returns a byte string.

std::string ciphertext, plaintext;
keyczar::Keyczar* crypter = keyczar::Crypter::Read("/path/to/your/keys");
if (!crypter ||
    !crypter->Encrypt("Secret message", &ciphertext)) {
  return 1;
if (!crypter->Decrypt(ciphertext, &plaintext)) return 1;
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.