[問題] RSA 加解密
我要加密一個檔案 已知道 公鑰(n,e) 私鑰(n,d)
我先用FileInputStream(檔案)讀進檔案
然後存到一個陣列中byte[] filecontent
再用base64 編碼成一個字串
String data=new sun.misc.BASE64Encoder().encode(filecontent);
接下來進行
[RSA加密]
byte[] encodingbyte = data.getBytes();//先把剛剛的字串轉byte[ ]
RSAEngine() rsa = new RSAEngine();
rsa.init(true, new RSAKeyParameters(false,n,e));
enRSAcode =rsa.processBlock(encodingbyte, 0, encodingbyte.length);
[RSA解密]
RSAEngine rsa = new RSAEngine();
rsa.init(false, new RSAKeyParameters(true,n,d));
deRSAcode = rsa.processBlock(enRSAcode, 0, enRSAcode.length);
String decodefile = new String(deRSAcode);
問題來了
我最後解密完的decodedfile內容 我把它印出來
卻跟我原來拿去加密的那個data的內容不一樣
請問為什麼為這樣呢? 比如說 拿去加密的字串String data = "qvy6T6uifn4NCg"
但解密完的decodefile應該也要是"qvy6T6uifn4NCg"
但我解密完卻是一堆有點像中文的亂碼 囧
我google好久 還是不知道為什麼> < 也看了RSAEngine( ) 的API了
謝謝各位大大 > <
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.139.133.87
推
05/28 10:30, , 1F
05/28 10:30, 1F
→
05/28 10:32, , 2F
05/28 10:32, 2F
→
05/28 13:40, , 3F
05/28 13:40, 3F
→
05/28 13:42, , 4F
05/28 13:42, 4F
推
05/28 13:51, , 5F
05/28 13:51, 5F
→
05/28 16:30, , 6F
05/28 16:30, 6F
推
06/03 00:26, , 7F
06/03 00:26, 7F