How to use the react-native-sodium.crypto_box_keypair 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
_testBox1() {
    this.setState({crypto_box1:null})
    const mlen_max = 1000

    Promise.all([Sodium.crypto_box_keypair(),Sodium.crypto_box_keypair()]).then(([alice,bob]) => {
      let p = []
      for (mlen = 0; mlen <= mlen_max; mlen++) {
        p.push(
          Promise.all([
            Sodium.randombytes_buf(Sodium.crypto_box_NONCEBYTES),
            Sodium.randombytes_buf(mlen)
          ]).then(([n,m]) =>
             Sodium.crypto_box_easy(m,n,bob.pk,alice.sk)
              .then((c) => Sodium.crypto_box_open_easy(c,n,alice.pk,bob.sk))
              .then((mm) => mm === m))
        )
      }
      Promise.all(p).then((pr) => {
        let fail = false
        for (i = 0; i < pr.length && !fail; ++i) if (!pr[i]) fail = true
        this.setState({crypto_box1:!fail})