How to use the react-native-sodium.randombytes_buf 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
_testRandom2() {
    this.setState({randombytes_buf:null})
    let freq = [];
    for (i = 0; i < 256; ++i) freq[i] = 0;
    Sodium.randombytes_buf(20*256).then((value) => {
      let a = Base64.toByteArray(value)
      for (i = 0; i < a.length; ++i) ++freq[a[i]]
      var fail = false
      for (i = 0; i < 256 && !fail; ++i) if (!freq[i]) fail = true
      this.setState({randombytes_buf:!fail})
    })
  }
github lyubo / react-native-sodium / Example / Example.js View on Github external
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})
      })
    })
  }