$ publicKey =“ ../ssh/public/pub”; $ plaintext =“要加密的字符串”;
$pubKey = openssl_pkey_get_public($publicKey);
openssl_public_encrypt($plaintext, $encrypted, $pubKey);
echo $encrypted; //encrypted string
Run Code Online (Sandbox Code Playgroud)
上面的代码生成以下错误
openssl_public_encrypt()[http://php.net/function.openssl-public-encrypt]:密钥参数不是有效的公用密钥[APP / controllers / supportservice_controller.php,第144行]
我使用以下命令使用openssl创建了密钥:
生成一个1024位的rsa私钥,要求输入密码以对其进行加密并将其保存到文件openssl genrsa -des3 -out / path / to / privatekey 1024
生成专用密钥的公用密钥并保存到文件
openssl rsa -in / path / to / privatekey -pubout -out / path / to / publickey
我有这个脚本,我希望光标专注于隐藏的字段,但它似乎没有工作.当我使该字段可见时,它似乎工作.
$(document).ready(function(){
$("#card_number").focus();
$("#card_number").keypress(function() {
alert($("#card_number").val());
});
});
Run Code Online (Sandbox Code Playgroud) 我可以加密小字符串,但是当它超过 118 个字符时似乎不起作用?任何的想法 ?
private function encryptData($plaintext) {
$plaintext = '{ "id":"1" "name":"Bottled Beer" "description":"" "parent_id":"111" "taxonomy":"SIMPLE_PLU" },{ "id":"2" "name":"Stout" }';
$publicKey = "../ssh_keys/coasts/public/pub.pem";
$fp=fopen($publicKey,"r");
$pub_key_string=fread($fp,8192);
fclose($fp);
$pubKey = openssl_pkey_get_public($pub_key_string);
openssl_public_encrypt($plaintext, $encrypted, $pubKey);
return $encrypted;
}
Run Code Online (Sandbox Code Playgroud)