简体   繁体   English

如何使用公钥加密字符串以在php中生成静态字符串而不是动态字符串?

[英]How can I encrypt a string using public key to generate a static string rather than a dynamic one in php?

I am trying to encrypt a string using a public key but each time I get a new string. 我正在尝试使用公共密钥对字符串进行加密,但是每次我得到一个新字符串时,我都会这样做。 Any workarounds to getting a static string? 任何获取静态字符串的解决方法?

Here is my code 这是我的代码

$publicKey = openssl_pkey_get_public(file_get_contents("file://C:/Users/nick/Dropbox/wamp/www/samples/mycert.cer"));
$plaintext = "Matr!x12";
openssl_public_encrypt($plaintext, $encrypted, $publicKey, OPENSSL_PKCS1_PADDING);
echo base64_encode($encrypted);

Well, obviously SSL encryption generates different results each time it's involved for security reasons. 好吧,显然出于安全原因,每次涉及SSL加密都会产生不同的结果。 If you for whatever reason you need to have identical results multiple times you cannot use "real encryption". 如果出于某种原因需要多次获得相同的结果,则不能使用“真实加密”。 Maybe just use MD5 or some other hash function but be aware that you cannot get secrets that cannot be decrypted (with enough effort). 也许只是使用MD5或其他某种哈希函数,但要注意,您无法获得无法解密的机密信息(需要付出足够的努力)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在php中使用私钥和公钥加密和解密大字符串? - How can I encrypt and decrypt large string using private key and public key in php? 是否可以在NodeJS中生成密钥对,使用公共密钥在PHP中加密数据以及在NodeJS中解密? - Can I generate a key-pair in NodeJS, encrypt data in PHP using the public key, and decrypt in NodeJS? 如何加密和解密 php 中的字符串? - How can I encrypt and decrypt a string in php? PHP使用多个公钥加密数据 - PHP Encrypt data with more than public key 在PHP中使用字符串作为“键”生成唯一的字符串 - Generate unique string using a string as a 'key' in PHP PHP:将加密查询字符串 (GET) 的表单示例(数据隐藏而不是安全性) - PHP : Form example which will encrypt query string (GET) (data hiding rather than security) 使用PHP使用Cryptico公钥加密消息 - Encrypt message with Cryptico public key using PHP 如何在PHP中加密字符串? - How do I encrypt a string in PHP? 使用PHP生成公钥/私钥对并将公钥导出为.der编码的字符串 - Use PHP to generate a public/private key pair and export public key as a .der encoded string 使用MYSQL PHP搜索每个单词而不是完整的字符串 - Searching by each word rather than complete string using MYSQL PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM