0

我想在服务器和客户端之间传输一个大文件,我知道该怎么做:对于客户端,代码如下:

OutputStream output = sk.getOutputStream();     

    FileInputStream fileInputStream = new FileInputStream(file);
    byte[] buffer = new byte[1024*1024];
    int bytesRead = 0;

    while((bytesRead = fileInputStream.read(buffer))>0)
    {
        output.write(buffer,0,bytesRead);
    }

    fileInputStream.close();

对于服务器端:

InputStream input = sk.getInputStream();

    file = new File(filename);
    FileOutputStream out = new FileOutputStream(file);

    byte[] buffer = new byte[1024*1024];

    int bytesReceived = 0;

    while((bytesReceived = input.read(buffer))>0) {
        out.write(buffer,0,bytesReceived);
        System.out.println(bytesReceived);
        break;
    }

现在的问题是,服务器和客户端同意一个 128 位的 AES 密钥,所以我想充分利用会话密钥来保证文件传输过程的安全。我的问题是,我在哪里可以在我的客户端和服务器中插入 AES 加密过程?谢谢!

4

1 回答 1

1

我认为您可以使用 javax.crypto.CipherInputStream / javax.crypto.CipherOutputStream。使用示例http://www.flexiprovider.de/examples/ExampleCrypt.html

于 2013-01-20T05:15:23.780 回答