react-native-aes
react-native-aes copied to clipboard
What should be the format of cipher and iv ?
Hi all,
I have a file where the iv is encoded in the first 16 bytes of data and then the rest is the actual file content (bytes 16 onwards). I'm using expo filesystem but I am lost as always the decypher fails.
let key = '<<KEY>>';
const encoding = FileSystem.EncodingType.Base64;
const fileInfo: any = await FileSystem.getInfoAsync(uri);
const size = fileInfo.size;
console.log(fileInfo);
const iv = await FileSystem.readAsStringAsync(uri, { encoding, length: 16, position: 0 });
const cipher = await FileSystem.readAsStringAsync(uri, { encoding, position: 16, length: size - 16 });
const text = await Aes.decrypt(cipher, key, iv, 'aes-256-ctr');
await FileSystem.writeAsStringAsync(targetUri, text);
Error:
WARN Possible Unhandled Promise Rejection (id: 0):
Error: Decrypt failed
Error: Decrypt failed
at promiseMethodWrapper (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.vetro.fibermap.mobile:2729:45)
at ?anon_0_ (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.vetro.fibermap.mobile:281287:61)
at next (native)
at asyncGeneratorStep (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.vetro.fibermap.mobile:27807:26)
at _next (http://localhost:8081/index.bundle//&platform=ios&dev=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.vetro.fibermap.mobile:27826:29)
at tryCallOne (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphonesimulator/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)