public function WardenAPI::decrypt in Warden 6
Same name and namespace in other branches
- 7 warden_api.inc \WardenAPI::decrypt()
Decrypt a message which was encrypted with the Warden private key.
Parameters
string $cypherText: The encrypted text
Return value
mixed The original data
Throws
Exception
File
- ./
warden_api.inc, line 133 - The API for communicating with the Warden server application.
Class
- WardenAPI
- @file The API for communicating with the Warden server application.
Code
public function decrypt($cypherText) {
$envelope = json_decode(base64_decode($cypherText));
if (!is_object($envelope) || empty($envelope->key) || empty($envelope->message)) {
throw new Exception('Encrypted message is not understood');
}
$key = base64_decode($envelope->key);
$message = base64_decode($envelope->message);
$decrypted = '';
$result = openssl_open($message, $decrypted, $key, $this
->getPublicKey());
if ($result === FALSE) {
throw new Exception('Unable to decrypt a message: ' . openssl_error_string());
}
return json_decode($decrypted);
}