doumie6223 2016-11-29 15:55
浏览 95
已采纳

golang rsa解密没有填充?

Golang rsa does not have NO_PADDING?
But openssl is ok. For encrypted data docking and other language, the encrypted data with Golang cannot decrypt normally, but the use of PHP and Openssl can be normal, later found like Golang does not support NO_PADDING decryption, seems to only PKCS1.
Openssl increase the parameter - raw can normal decryption.The private key is above, a cipher and decrypted correct value.
Can someone help me to look at how to solve?

$ cat private.pem  
-----BEGIN RSA PRIVATE KEY-----  
MIIBOgIBAAJBANJS/xu+NtmDqobnhCdLjWk46aYbBk/mQrLcozAIbQLFG2mgkrxf  
B5+CgtISKpKfmRfCO2NhceK+YedaMMBUxn8CAQMCQQCMN1S9KXnmV8cEmlgaMl5G  
JfEZZ1mKmYHMkxd1WvNXLNuke9ntKwti8zG1lAFcOVHnm/uYsNdua+lvvQlEgBUL  
AiEA/c8ezGaNUFwEAltwTEFtFItT5PyOXlWIdPAZ7j160lkCIQDUI8f/chEmLxG1  
5kPcRtyJsQRdAcnQZ5QOz6S0nBnUlwIhAKk0vzLvCOA9WAGSSt2A82MHjUNTCZQ5  
BaNKu/Qo/Iw7AiEAjW0v/6FgxB9hI+7X6C89sSCtk1aGiu+4Cd/DIxK74w8CIB4q  
rA1k247JrqKTGlqSHVr1Ta+h3BPbwFKCi5CiDOjV  
-----END RSA PRIVATE KEY-----  

$ xxd data.txt  
00000000: 6d4b 5dab 6d64 45e1 e4cb 0ea8 20df b724  mK].mdE..... ..$  
00000010: cfe5 db3e 75c4 e80e 2337 4f08 1b36 87b4  ...>u...#7O..6..  
00000020: 7550 47d4 ed60 576a a160 2d01 3cf7 4c50  uPG..`Wj.`-.<.LP  
00000030: 7e44 6432 1f9d cfe2 2e9f 4f89 f815 ae01  ~Dd2......O.....  

$ base64 -i data.txt  
bUtdq21kReHkyw6oIN+3JM/l2z51xOgOIzdPCBs2h7R1UEfU7WBXaqFgLQE890xQfkRkMh+dz+Iun0+J+BWuAQ==  

$ cat data.txt | openssl rsautl -decrypt -inkey private.pem -raw  
qYnYKT2mxuXR5XB615gOenqxOnIUjWs7
  • 写回答

2条回答 默认 最新

  • douben7493 2016-12-01 16:07
    关注

    Decrypting a ciphertext block using rsa with no padding is a single modulo exponent operation.

    c := new(big.Int).SetBytes(cipherText)
    plainText := c.Exp(c, privateKey.D, privateKey.N).Bytes()
    

    A full example using your input data is here: https://play.golang.org/p/CgLYgLR61t

    If you want a full version of the decryption function, with side-channel blinding and using precomputed CRT values for faster performance, you can copy the decrypt function from the crypto/rsa/rsa.go source.

    If you have the choice, you should not be using rsa in this manner. There is a good discussion on the Crypto StackExchange site explaining the details and drawbacks of using this method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型