简体   繁体   English

RSA-BIgInteger问题

[英]RSA- BIgInteger Issue

I want to use RSA algorithm , for encrypt and decrypt messages. 我想使用RSA算法 ,用于加密和解密消息。 Now, as RSA can encrypt and decrypt Big-integer (or Integer) value, I need the message as Big-integer value. 现在,由于RSA可以加密和解密大整数(或整数)值,我需要将消息作为大整数值。 Now, message can contain strings like "ABC 123". 现在,消息可以包含“ABC 123”之类的字符串。 What can I do ? 我能做什么 ? Any help or suggestion ? 任何帮助或建议?

If your message is initially ascii, you can use something like: 如果您的消息最初是ascii,则可以使用以下内容:

BigInteger i = new BigInteger();
While(j < msg.length() ) {
  i += ((byte)msg.charAt(j) << (j*7));
}

For working code consult the actual JavaDocs. 有关工作代码,请参阅实际的JavaDocs。 But basically you just want to turn your bytes or chars into a number, so the idea is you just concatenate the bits together. 但基本上你只想把你的字节或字符变成一个数字,所以你只想把这些位连接在一起。

It can be done, by using 它可以通过使用来完成

byte[] b = message.getBytes()
BigInteger = new BigInteger (b) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM