我已经设置了一个服务器,它通过下面提到的 java 函数侦听加密的字节数组。早些时候,我使用 java (android) 来构建我的应用程序,因此使用相同的 java 函数很容易,但我无法弄清楚该函数的 dart 等效项(flutter)是什么,该函数接受字符串作为输入并返回 AES 加密字节数组作为输出,我可以将其写入 TCP 套接字。
另外,我非常感谢您帮助了解如何将生成的字节数组写入服务器,然后读取类似的响应并通过 dart (颤振)对其进行解密
我已经成功地编写了简单的字符串并通过 dart 接收简单的字符串作为 tcp 服务器的输入和输出,但无法对加密的字节数组执行相同的操作。在java中,我使用DataOutputStream将响应发送到服务器,如下所示
DataOutputStream dOut = newDataOutputStream(socket.getOutputStream());
byte[] s2 = Encrypt3.encrypt2(myString);
dOut.writeInt(s2.length); // write length of the message
dOut.write(s2);
Run Code Online (Sandbox Code Playgroud)
这是我用于aes加密的java函数
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class Encrypt3 {
public static String key = "mykey";
public static byte[] encrypt2(String text ){
String encrypt ="";
try{
// Create key and cipher
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES"); …Run Code Online (Sandbox Code Playgroud)