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

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条)

相关推荐 更多相似问题