- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我可以使用 jsbn 成功生成公钥/私钥对在客户端。使用这些 key 加密和解密客户端是可以的。我还可以将该公钥传输到服务器并通过 PHP 将其存储在 MySQL 中。
我无法使用 jsbn 公钥在 PHP 中加密某些内容,然后使用 jsbn 私钥在客户端对其进行解密。
// attempting to encrypt in PHP using the jsbn public key.
// (this public key came from jsbn client side)
$jsbn_public_key = '763989d1f75a779dae752ac236b011e85f9496bb414d72f5e89bf44274a942277fab2d4f5c58a57634d4000eecc8009d2efaeff17aa4a0efae2c4d41f3423be88be043628c6bac86f97deaadf23231793e6fa02550fb2ca65b2600e074205d23338e28ab3c5e92265e6bd7995c173085e3dc042e59ef464c5ed058c3ad863911';
$rsa = new Crypt_RSA();
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); // tried various options here.
$public_key = array(
'n' => new Math_BigInteger($jsbn_public_key, 16),
'e' => new Math_BigInteger('65537', 10), // same value as jsbn
);
$rsa->loadKey($public_key,CRYPT_RSA_PUBLIC_FORMAT_RAW); // tried various options here.
$ciphertext = $rsa->encrypt($value);
$ciphertext_web_safe = bin2hex($ciphertext); // I think this is where the problem is!
// $ciphertext_web_safe looks something like this:
// 1b02bee0422028accba74f37e6e6974125fd16bdf83a72b8d6462e140ee6e85adae869fddc5e83635aaf90bc6074a3128890eeadf9537c33ebdfd665e16a3f1b617fa2fa5454f469e84f86d77ffcbc234dfc8a32291fbc84df61a0098c97fd90bb10204f68e783d9996678cd7853f3cbd932a4a067cb7f4f9eb62ca0542964f6
// which is exactly the same length as an encrypted string generated by jsbn
这是客户端加密:
var my_rsa = {
....
e: "65537",
public_key: '763989d1f75a779dae752ac236b011e85f9496bb414d72f5e89bf44274a942277fab2d4f5c58a57634d4000eecc8009d2efaeff17aa4a0efae2c4d41f3423be88be043628c6bac86f97deaadf23231793e6fa02550fb2ca65b2600e074205d23338e28ab3c5e92265e6bd7995c173085e3dc042e59ef464c5ed058c3ad863911',
encrypt: function(value){
var rsakey = new RSAKey();
rsakey.setPublic(this.public_key, this.e);
return rsakey.encrypt(value);
},
decrypt: function(ciphertext){
var rsakey = new RSAKey();
rsakey.setPrivateEx(this.public_key, this.e, this.private_key.d, this.private_key.p, this.private_key.q, this.private_key.dmp1, this.private_key.dmq1, this.private_key.coeff);
return rsakey.decrypt(ciphertext);
},
....
};
当我尝试在 JavaScript 中解密“$ciphertext_web_safe”值时,我只是得到一个空字符串。控制台日志等中没有错误。
PHP中使用的“bin2hex”有问题吗?在将加密的二进制数据转换为十六进制之前,是否应该应用某种填充等?
干杯,戴夫
最佳答案
我的问题是 javascript 中的“e”。
我将“65537”更改为“010001”,现在我可以使用公钥和 PHP 加密服务器端。呸!
关于phpseclib/jsbn : encrypt with public key in PHP, 在jsbn中用私钥解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11293589/
有人可以向我解释该声明在C++中的含义吗?我从未见过这样的声明,只是对它的含义和作用感到困惑: int ix((dx > 0) - (dx > 1)); 最佳答案 您可以在括号或花括号中使用初始化程序
我有一个带有单词的mysql数据库。我用 while 语句打印所有单词。所以我觉得: 马铃薯番茄生菜 一切正常,但我想按长度对单词进行排序。我试过: if(strlen($go['words']) =
我忠实的路径遍历方法不再有效——它将空格视为分隔符。好久没做批处理编程了。 使用 FOR 循环时,唯一允许使用分隔符的是 FOR/F 选项。 我不想创建一个包含路径的临时文件,希望做如下的事情: C:
新建一个表: ? 1
我有一些带有多行块的文本文件,例如 2011/01/01 13:13:13,, Some Certain Text,=, [ certain text [
我想在 Vim 中文件的不同部分之间进行一些很好的分离: 我想用#'s 填充一行,然后在中间写上我的标题: ############################# 居中标题############
我该如何逃生 "*"至 "\*"在clojure?似乎无法让它工作: (s/replace "A*B" #"*" "*")生产 "A*B" (当然) (s/replace "A*B" #"*" "\*
这周我一直在努力更熟悉 C。我一直在阅读C Primer Plus (5th Edition) 但是我仍然在使用变量和指针时遇到了一些麻烦。 这是我用来测试的脚本: int main (int arg
在 Dart 中,初始化 List 有什么区别?使用 new 运算符并使用文字对其进行初始化? 情况1: List args = new List(2); args[0] = 1; args[1] =
我有一个字符向量,如下所示: "Internet" "Internet" "-1" "-5" "Internet" "Internet" 我想替换所有负数值的值(-1、-5 等
我有一个名为 gen 的数据框,如下所示 A B C D E 1 NA 4.35 35.3 3.36 4.8
我有一个字符向量,如下所示: "Internet" "Internet" "-1" "-5" "Internet" "Internet" 我想替换所有负数值的值(-1、-5 等
我想知道为什么 CMake 中的变量经常用美元符号和大括号括起来。例如,我看到这个电话in a CMake tutorial . include_directories(${PROJECT_BINAR
我正在尝试做这样的事情 $this->db->count_all("grant_money")->where('id',5); 这可能吗? 如果有任何其他方法可以做到这一点,请告诉我。谢谢 我想像上面
为什么这是有效的: int a = 5; int *aPtr = &a; printf("%i", *aPtr); 但这不是: int a = 5; int aPtr = &a; printf("%i
假设我有一个格式为“11.23.13”的日期字符串,我想用“/”替换每个点,使其看起来像“11/23/13”。 这是我的代码,但它无法正常工作,因为正则表达式看到“.”并将其解释为匹配每个字符而不是新
如何在键盘输入的字符处打印*? 例子: 如果我在控制台中输入:mouli,那么它应该将 m 替换为 *,然后是 o用 * 等等。 最佳答案 使用标准 API 无法解决此问题。如果这确实是一个明确的要求
我最近开始学习 Javascript,同时对卡在这段代码中的代码进行了一些实验: var k = { ab: "hi", func: function() { cons
我需要用“.”替换第一列中的重复项 例如: name1 name1 name1 name2 name2 name3 name3 我需要输出: name1 . . name2 . name3 . 我有这
我有以下两个表 education 和 jobs,每个表都有时间戳字段。在续集语句中,我想选择并确定两个表中保存的两个时间戳中哪个是最新的。 我已经尝试了以下但并不愉快; SELECT e.Sta
我是一名优秀的程序员,十分优秀!