私はJavaのソケットを介してバイト配列を転送するアプリケーションを書いています。
クライアント側でのバイト配列の生成は次のとおりです。
String vote = br.readLine();
// the data that i now encrypt using RSA
PublicKey pubKey = readKeyFromFilepublic("alicepublic.txt");
Cipher cvote = Cipher.getInstance("RSA");
cvote.init(Cipher.ENCRYPT_MODE, pubKey);
byte[] voted = cvote.doFinal(vote.getBytes());
System.out.println(voted);
out.println(voted.length);
dos.write(voted,0,voted.length); // here i am sending the array to the server
サーバー側で私は書く
String clen = in.readLine(); // read the length
byte[] array = new byte[Integer.parseInt(clen)]; // create the array of that length
dist.readFully(array); // read the array
// i am unable to read the array here at all !
PrivateKey priKey = readKeyFromFileprivate("aliceprivate.txt");
Cipher vote = Cipher.getInstance("RSA");
vote.init(Cipher.DECRYPT_MODE, priKey);
byte[] voteData = vote.doFinal(array);
System.out.println(voteData);
// finally print the decrypted array
正しく機能するファイルに書き込むことで、暗号化と復号化のプロセスを確認しました。
両端でDataInputストリームとDataOutputストリームを使用しています。
私のコードの何が問題なのか教えてください!