php-aes加密rsa公钥加密

巫马瀚漠
2023-12-01
$jsonStr = json_encode($cInfoArray, 1);
//AES加密
$cInfo = self::AESEncrypt($jsonStr, $aesKey);
//RSA 公钥加密aesKey
openssl_public_encrypt($aesKey, $encrypted, file_get_contents(VISITOR_CARD_PUB_KEY));

//RSA 公钥解密
openssl_public_decrypt(base64_decode($key), $decrypted, file_get_contents(VISITOR_CARD_PUB_KEY));

//AES解密 params
$aesParams = self::AESDecrypt($params, $decrypted);
 private static function AESEncrypt($str, $key)
    {
        return openssl_encrypt($str, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
    }

private static function AESDecrypt($strEncode, $key)
    {
        return openssl_decrypt(base64_decode($strEncode), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
    }
 类似资料: