mvayngrib/react-native-aes

语言: Objective-C

git: https://github.com/mvayngrib/react-native-aes

反应原生的加密/解密
aes encryption/decryption in react native
README.md (中文)

反应天然-AES

AES加密/解密反应原生

支持的密码

  • AES-256-CBC

用法

var AES = require('react-native-aes')
var Buffer = require('buffer').Buffer

var stringInput = 'hey ho'
var bufferInput = new Buffer(stringInput)
// sample key
var key = new Buffer('f0ki13SQeRpLQrqk73UxhBAI7vd35FgYrNkVybgBIxc=', 'base64')
var cipherName = 'AES-256-CBC'
AES.encryptWithCipher(
  cipherName,   // String
  bufferInput,  // Buffer (input data)
  key,          // AES key, e.g. 32 bytes of random data
  function (err, encrypted) {
//  "encrypted" is of the form
//  {
//    ciphertext: Buffer,
//    iv: Buffer
//  }
//
//  you'll need both parts to decrypt

    AES.decryptWithCipher(
      cipherName,             // String
      encrypted.ciphertext,   // Buffer (input data)
      key,
      encrypted.iv,           // Buffer
      function (err, plaintext) {
        // plaintext is a Buffer
        if (plaintext.toString() !== stringInput) {
          throw new Error('time to report an issue!')
        }
      }
    )
  }
)

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

react-native-aes

AES encryption/decryption in react native

Supported Ciphers

  • AES-256-CBC

Usage

var AES = require('react-native-aes')
var Buffer = require('buffer').Buffer

var stringInput = 'hey ho'
var bufferInput = new Buffer(stringInput)
// sample key
var key = new Buffer('f0ki13SQeRpLQrqk73UxhBAI7vd35FgYrNkVybgBIxc=', 'base64')
var cipherName = 'AES-256-CBC'
AES.encryptWithCipher(
  cipherName,   // String
  bufferInput,  // Buffer (input data)
  key,          // AES key, e.g. 32 bytes of random data
  function (err, encrypted) {
//  "encrypted" is of the form
//  {
//    ciphertext: Buffer,
//    iv: Buffer
//  }
//
//  you'll need both parts to decrypt

    AES.decryptWithCipher(
      cipherName,             // String
      encrypted.ciphertext,   // Buffer (input data)
      key,
      encrypted.iv,           // Buffer
      function (err, plaintext) {
        // plaintext is a Buffer
        if (plaintext.toString() !== stringInput) {
          throw new Error('time to report an issue!')
        }
      }
    )
  }
)