cryptico.js java解密_用Cryptico.js加密,用OpenSSL解密

我正在服务器上创建一个公钥/私钥,将密钥发送到JavaScript客户端,在那里加密用户密码 . 客户端将密码发送到服务器,服务器使用私钥对其进行解密,但密码将返回null . 我已经验证了支持这种情况的所有值都是正确的,所以具体来说就是加密/解密 . 我哪里错了?

可能,cryptico.js与php openssl不兼容吗?

图书馆信息:

以下是相关的代码段:

PHP - create public/private key

$config = array(

"digest_alg" => "sha512",

"private_key_bits" => 2048,

"private_key_type" => OPENSSL_KEYTYPE_RSA,

);

// Create the private and public key

$res = openssl_pkey_new($config);

// Extract the private key from $res to $privateKey

openssl_pkey_export($res, $privateKey);

// Extract the public key from $res to $publicKey

$publicKey = openssl_pkey_get_details($res);

$publicKey = $publicKey["key"];

JavaScript - Client encrypts data with public key.

var xhr = new XMLHttpRequest();

var data = new FormData();

xhr.open('POST', '/signUp2.php');

data.append('user', User);

var encryptedPassword = cryptico.encrypt(password, localStorage["publicKey"]);

data.append('password', encryptedPassword.cipher);

xhr.onreadystatechange = function()

{

if(xhr.readyState == 4 && xhr.status == 200)

{

var jsonArray = JSON.parse(xhr.responseText);

if(jsonArray[0] == "0")

{

alert("Account created. You may now sign in.");

}

else

alert("Error Code: " + jsonArray[0]);

}

}

xhr.send(data);

PHP - Server recieves encrypted password and attemps to decrypt unsuccessfully

openssl_private_decrypt($encryptedPassword, $decryptedPassword, $row[1]);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值