示例#1
0
 public static function factoryFromEncrypted($envKey, $encData, $privateKeyFilePath, $privateKeyPassword = null)
 {
     $privateKey = null;
     if ($privateKeyPassword == null) {
         $privateKey = @openssl_get_privatekey($privateKeyFilePath);
         if ($privateKey === false) {
             $privateKey = @openssl_get_privatekey("file://{$privateKeyFilePath}");
         }
     } else {
         $privateKey = @openssl_get_privatekey($privateKeyFilePath, $privateKeyPassword);
         if ($privateKey === false) {
             $privateKey = @openssl_get_privatekey("file://{$privateKeyFilePath}", $privateKeyPassword);
         }
     }
     if ($privateKey === false) {
         throw new \Exception('Error loading private key', self::ERROR_CONFIRM_LOAD_PRIVATE_KEY);
     }
     $srcData = base64_decode($encData);
     if ($srcData === false) {
         @openssl_free_key($privateKey);
         throw new \Exception('Failed decoding data', self::ERROR_CONFIRM_FAILED_DECODING_DATA);
     }
     $srcEnvKey = base64_decode($envKey);
     if ($srcEnvKey === false) {
         throw new \Exception('Failed decoding envelope key', self::ERROR_CONFIRM_FAILED_DECODING_ENVELOPE_KEY);
     }
     $data = null;
     $result = @openssl_open($srcData, $data, $srcEnvKey, $privateKey);
     if ($result === false) {
         throw new \Exception('Failed decrypting data', self::ERROR_CONFIRM_FAILED_DECRYPT_DATA);
     }
     return RequestAbstract::factory($data);
 }