fun getEncryption(password: String): String {
val salt = "abcdefghijkl"
Aes256.encrypt(password, salt)
}
}
public class Aes256 extends AbstractAes256
{
public static String encrypt(String input, String passphrase) throws Exception {
return Base64.getEncoder().encodeToString(_encrypt(input.getBytes(UTF_8), passphrase.getBytes(UTF_8)));
}
}
我需要使用与上面在flutter中相同的方法来加密字符串。 有人知道如何在 flutter 中获得类似的功能吗?
在 Flutter 中,您可以使用
encrypt
包进行 AES 加密。首先,您需要将 encrypt
包添加到您的 pubspec.yaml
文件中:
dependencies:
encrypt: ^5.0.1
然后,您可以创建一个执行 AES 加密的 Dart 函数:
import 'dart:convert';
import 'package:encrypt/encrypt.dart';
String getEncryption(String password) {
final salt = 'abcdefghijkl'; // Replace with your salt value
final key = Key.fromUtf8(salt);
final iv = IV.fromLength(16); // Use a random IV for better security
final encrypter = Encrypter(AES(key, mode: AESMode.cbc, padding: null));
final encrypted = encrypter.encrypt(password, iv: iv);
return base64Encode(encrypted.bytes);
}
void main() {
final password = 'YourPassword';
final encryptedPassword = getEncryption(password);
print('Encrypted Password: $encryptedPassword');
}
确保将
'abcdefghijkl'
替换为您的实际盐值。