如何从 J2ME 中的字符串加载 RSA 公钥
我需要通过短信在J2ME中进行一些加密。该应用程序以字符串形式接收短信中的公钥,与 openssl 从私钥创建公钥的方式相同,这就是创建密钥的方式:
- 私钥:openssl genrsa -out privkey.pem 144
- 公钥:openssl rsa -in privkey .pem -out pubkey.pem
字符串是用类似这样的东西创建的,这是公钥:
MGwCAQACEwCxcz+Qk8J6CptiRg6EBpG6SHECAwEAAQISVTLKcDYhh8sTJggObTKI
pdIJAgoA7EwFr5Un3AErAgoAwD8WTwqL0vbTAgoAkuPfVPr/wD/pAgl44rKqfR0z
SRUCCgDDqC/pMSBHTJs=
现在,如何在源代码中获取此公钥RSAPublicKey
准备好在密码中使用了吗?
为此:
byte[] plaintext="some text".getBytes();
byte[] encryptedtext;
Cipher cipher=Cipher.getInstance("RSA");
RSAPublicKey pubKey=new RSAPublicKey(????????);
cipher.init(Cipher.ENCRYPT_MODE,pubkey);
cipher.doFinal(plaintext,0,plaintext.length,encryptedtext,0)
I need to do some encryption in J2ME through sms. The app receives the public key in an sms as String, the same way openssl creates Public key from Private key, this is how the keys are created:
- Private Key: openssl genrsa -out privkey.pem 144
- Public key: openssl rsa -in privkey.pem -out pubkey.pem
The String is created with something like this, which is the public key:
MGwCAQACEwCxcz+Qk8J6CptiRg6EBpG6SHECAwEAAQISVTLKcDYhh8sTJggObTKI
pdIJAgoA7EwFr5Un3AErAgoAwD8WTwqL0vbTAgoAkuPfVPr/wD/pAgl44rKqfR0z
SRUCCgDDqC/pMSBHTJs=
Now, how to get to the point in a source code to get this public key in a RSAPublicKey
ready to be used in a cipher?
To do this:
byte[] plaintext="some text".getBytes();
byte[] encryptedtext;
Cipher cipher=Cipher.getInstance("RSA");
RSAPublicKey pubKey=new RSAPublicKey(????????);
cipher.init(Cipher.ENCRYPT_MODE,pubkey);
cipher.doFinal(plaintext,0,plaintext.length,encryptedtext,0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论