Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should be the format of cipher and iv ? #81

Open
grillorafael opened this issue Nov 6, 2023 · 0 comments
Open

What should be the format of cipher and iv ? #81

grillorafael opened this issue Nov 6, 2023 · 0 comments

Comments

@grillorafael
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant