2012-01-01 69 views
3

我想用RSA algorithm来加密和解密消息。现在,由于RSA可以加密和解密Big-integer(或Integer)值,所以我需要将该消息作为Big-integer值。现在,消息可以包含诸如“ABC 123”之类的字符串。我能做什么 ?任何帮助或建议?RSA- BIgInteger问题

+2

“我需要为大整数消息” - ??? – 2012-01-01 03:38:46

+1

加密算法加密字节的字符串。 – 2012-01-01 03:47:29

回答

2

这是可以做到,通过使用

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

很酷。和酷。 – 2012-01-01 09:26:00

2

如果你的消息最初是ASCII码,你可以使用类似:

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

对于工作代码参考实际的JavaDoc。但基本上你只是想把你的字节或字符变成一个数字,所以你的想法就是把这些位串联起来。

+0

谢谢gotafex。我发现另一种方式,发布如下。 – Arpssss 2012-01-01 04:08:21