Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加密问题 #1

Open
mjwSilence opened this issue May 29, 2023 · 2 comments
Open

加密问题 #1

mjwSilence opened this issue May 29, 2023 · 2 comments

Comments

@mjwSilence
Copy link

如果我只有私钥的字符串,依靠这个字符串创建一个Pem对象,这样每次是不是都会生成不同的publickey 和privatekey?
也就是说别的地方可以用这个私钥字符串解密的数据,在这里新创建的privatekey其实是无法解密的?
这个pem对象只能解密自己加密出来的数据对吗?

@mjwSilence
Copy link
Author

补充一个想请教的问题:现在我固定参数之后,Encode每次加密的结果仍然是不一样的,publicKey的encode每次都是一样的,但不清楚为什么加密的结果是每次都不一样

@xiangyuecn
Copy link
Owner

已经过去很久了哈,同一个私钥,构造出来的key都是相同的,得到的publicKey、privateKey都是相同的(但为不同的对象实例),不管在哪加密的,只要是这个相同私钥,就能解密。

RSA加密有填充,会在数据开头填充若干随机数数据(增加安全性),导致每次加密结果不相同,RSA默认RSA/ECB/PKCS1Padding为RSAES-PKCS1-v1_5填充,强制使用RSA/ECB/NoPadding不加填充就每次加密结果就都相同了。同样的,不管每次加密结果相同还是不相同,只要是相同的密钥和加密算法就能正确解密。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants