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

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 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化