I’ve a requirement the place a string can be encrypted from flutter net app utilizing Dart. The encrypted string goes to server and the identical can be consumed by iOS Swift.
Dart file
String encryptString(Uint8List key) {
attempt {
// Convert the important thing bytes into an encryption key
ultimate encryptionKey = Key(key);
// Generate a random IV (Initialization Vector)
ultimate iv = IV.fromSecureRandom(16); // 16 bytes IV for AES-GCM
ultimate macValue = Uint8List.fromList(utf8.encode("take a look at"));
// Create an AES encrypter with the important thing
ultimate encrypter = Encrypter(AES(encryptionKey));
// Encrypt the plaintext utilizing AES-GCM
ultimate encrypted = encrypter.encrypt(
this,
iv: iv,
associatedData: macValue
);
// Concatenate IV and ciphertext, then encode to base64
ultimate concatenatedBytes = Uint8List.fromList([...iv.bytes, ...encrypted.bytes, ...utf8.encode("test")]);
ultimate base64Encoded = base64.encode(concatenatedBytes);
//ultimate mixed = iv.bytes + encrypted.bytes;
return (base64Encoded);
} catch (e) {
print('Error whereas encrypting: $e');
return '';
}
}
Nonetheless the encrypted textual content I’m not in a position to decrypt in Swift. I all the time get CryptoKit.CryptoKitError.authenticationFailure
Swift code
func decrypt(withKey key: SymmetricKey) throws -> String {
guard let encryptedData = Knowledge(base64Encoded: self) else { throw EncryptionError.invalidData }
// Open the sealed field utilizing the encryption key
do {
let sealedBox = attempt AES.GCM.SealedBox(mixed: encryptedData)
// Decrypt the info
let decryptedData = attempt AES.GCM.open(sealedBox, utilizing: key)
// Convert decrypted information to string
guard let decryptedString = String(information: decryptedData, encoding: .utf8) else {
throw EncryptionError.decryptionFailed
}
return decryptedString
} catch {
print(error.localizedDescription)
throw EncryptionError.invalidData
}
}
I attempted the above snippets. Appears to not work, Please assist 🙁
Redmi 13C (Stardust Black, 6GB RAM, 128GB Storage) | Powered by 4G MediaTek Helio G85 | 90Hz Display | 50MP AI Triple Camera
₹8,799.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Oneplus 80W Charging Cable USB to Type C Warp Charger SuperVooc/Dash Fast Charge Cable for Oneplus 11,11R,10 Pro,10R,10T,9RT,9R,8R,8T Charge Cable for 6/6T/7/7T,Nord,Ce2 Lite 5G,Ce 3 5G,Ce3 Lite, Red
₹299.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Boult Audio [Just Launched] UFO True Wireless in Ear Earbuds with 48H Playtime, Built-in App Support, 4 Mics Clear Calling, Low Latency Gaming, Made in India Bluetooth 5.3 TWS Ear Buds (White Opal)
₹1,499.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Fire-Boltt Ninja Call Pro Plus 1.83" Smart Watch with Bluetooth Calling, AI Voice Assistance, 100 Sports Modes IP67 Rating, 240 * 280 Pixel High Resolution
₹1,099.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)OnePlus Nord CE 3 Lite 5G (Pastel Lime, 8GB RAM, 128GB Storage)
₹17,999.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)STRIFF Adjustable Laptop Tabletop Stand Patented Riser Ventilated Portable Foldable Compatible with MacBook Notebook Tablet Tray Desk Table Book with Free Phone Stand (Black)
₹299.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)TP-Link AC750 Wifi Range Extender | Up to 750Mbps | Dual Band WiFi Extender, Repeater, Wifi Signal Booster, Access Point| Easy Set-Up | Extends Wifi to Smart Home & Alexa Devices (RE200)
₹1,799.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Toysbuddy Re-Writable LCD Writing Tablet Pad with Screen 21.5cm (8.5Inch) for Drawing, Playing, Handwriting Best Birthday Gifts for Adults & Kids Girls Boys, Multicolor
₹139.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Logitech B170 Wireless Mouse, 2.4 GHz with USB Nano Receiver, Optical Tracking, 12-Months Battery Life, Ambidextrous, PC/Mac/Laptop - Black
₹595.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Portronics Konnect L POR-1403 Fast Charging 3A Type-C Cable 1.2 Meter with Charge & Sync Function for All Type-C Devices (White)
₹119.00 (as of April 1, 2024 14:09 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Auto Amazon Links: No products found.