关于php:PHPRSA加密解密

36次阅读

共计 852 个字符,预计需要花费 3 分钟才能阅读完成。

<?php
/**
* App RSA 加密解密辅助函数
**/
function app_pri_encrypt($data){$privateKey = openssl_pkey_get_private(file_get_contents("app-private.key"));
    $encrypted = null;
    openssl_private_encrypt($data,$encrypted,$privateKey);
    return base64_encode($encrypted);
}
function app_pri_decrypt($data){$privateKey = openssl_pkey_get_private(file_get_contents("app-private.key"));
    $decrypted = null;
    openssl_private_decrypt(base64_decode($data),$decrypted,$privateKey);
    return $decrypted;
}
function app_pub_encrypt($data){$publicKey = openssl_pkey_get_public(file_get_contents("app-public.key"));
    $encrypted = null;
    openssl_public_encrypt($data,$encrypted,$publicKey);
    return base64_encode($encrypted);
}
function app_pub_decrypt($data){$publicKey = openssl_pkey_get_public(file_get_contents("app-public.key"));
    $decrypted = null;
    openssl_public_decrypt(base64_decode($data),$decrypted,$publicKey);
    return $decrypted;
}

正文完
 0