How to use the react-native-sodium.crypto_auth function in react-native-sodium

To help you get started, we’ve selected a few react-native-sodium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyubo / react-native-sodium / Example / Example.js View on Github external
// Jefe
      0x4a,0x65,0x66,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]))

    const c = Base64.fromByteArray(new Uint8Array([
      // what do ya want for nothing?
      0x77,0x68,0x61,0x74,0x20,0x64,0x6f,0x20,0x79,0x61,0x20,0x77,0x61,0x6e,
      0x74,0x20,0x66,0x6f,0x72,0x20,0x6e,0x6f,0x74,0x68,0x69,0x6e,0x67,0x3f]))

    const a = Base64.fromByteArray(new Uint8Array([
      0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3,
      0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54]))

    this.setState({crypto_auth:null,crypto_auth_verify:null})

    Sodium.crypto_auth(c,k).then((aa) => {
      this.setState({crypto_auth:(a === aa)})
      Sodium.crypto_auth_verify(a,c,k)
        .then((r) => this.setState({crypto_auth_verify:(r == 0)}))
        .catch((error) => {
          this.setState({crypto_auth_verify:false})
          this._handleError(error)
        })
    }).catch((error) => {
      this.setState({crypto_auth_verify:false})
      this._handleError(error)
    })
  }