I am encrypting a file in Swift with way (using Apple CryptoKit), in AES-256:
let jsonData = try Data(contentsOf: jsonPath)
let skey = SymmetricKey(size: .bits256)
let dataSkey = skey.withUnsafeBytes {Data(Array($0)).base64EncodedString()}
print(dataSkey) // DeDGtpqvojYL32bIsEsaaXZITjJp4bAW7aQgtVYARO0=
let aes = try AES.GCM.seal(jsonData, using: skey)
try aes.combined!.write(to: encryptedPath)
// UPLOAD FILE (encryptedPath) TO FIREBASE STORAGEs
I am then trying to decrypt the file in Flutter (.dart) with this pub this way:
import 'package:steel_crypt/steel_crypt.dart';
final File tmpFile = File(//path of file downloaded from storage firebase);
var aesEncrypter = AesCrypt('DeDGtpqvojYL32bIsEsaaXZITjJp4bAW7aQgtVYARO0=', 'gcm', 'pkcs7');
String decrypted = aesEncrypter.decrypt(tmpFile.readAsStringSync());
print(decrypted);
But I always get this error:
"FileSystemException: Failed to decode data using encoding 'utf-8', path =path.file.json"
What am I doing wrong? I tried to encode the file from swift in base64 and read it again in flutter with base64 without success.