craftzdog / react-native-aes-gcm-crypto

AES-GCM encryption/decryption for React Native
MIT License
248 stars 29 forks source link
cryptography react-native

react-native-aes-gcm-crypto

AES-GCM encryption/decryption for React Native

Requirements

Installation

npm install react-native-aes-gcm-crypto

Usage

import AesGcmCrypto from 'react-native-aes-gcm-crypto';

const key = 'Yzg1MDhmNDYzZjRlMWExOGJkNTk5MmVmNzFkOGQyNzk=';

AesGcmCrypto.decrypt(
  'LzpSalRKfL47H5rUhqvA',
  key,
  '131348c0987c7eece60fc0bc',
  '5baa85ff3e7eda3204744ec74b71d523',
  false
).then((decryptedData) => {
  console.log(decryptedData);
});

AesGcmCrypto.encrypt('{"name":"Hoge"}', false, key).then((result) => {
  console.log(result);
});

Encrypt data

type EncryptedData = {
  iv: string;
  tag: string;
  content: string;
};

function encrypt(
  plainText: string,
  inBinary: boolean,
  key: string
): Promise<EncryptedData>;

Encrypt file

function encryptFile(
  inputFilePath: string,
  outputFilePath: string,
  key: string
): Promise<{
  iv: string;
  tag: string;
}>;

Decrypt data

function decrypt(
  base64Ciphertext: string,
  key: string,
  iv: string,
  tag: string,
  isBinary: boolean
): Promise<string>;

Decrypt file

function decryptFile(
  inputFilePath: string,
  outputFilePath: string,
  key: string,
  iv: string,
  tag: string
): Promise<boolean>;

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Author

Takuya Matsuyama | @inkdrop_app

Made for my app called Inkdrop - A Markdown note-taking app

License

MIT