加密 – React-Native加密:如何在React-Native中生成HMAC?

前端之家收集整理的这篇文章主要介绍了加密 – React-Native加密:如何在React-Native中生成HMAC?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过加密,这显然不起作用,因为它取决于节点运行.所以,我转向 crypto-browserify,但我相信存在依赖性问题.如果有人能提供帮助,我会非常感激.

作为参考,我之前使用过像这样的加密:

crypto.createHmac('md5',"MY_KEY").update('SOMETHING_TO_ENCRYPT').digest('hex');

编辑

我正在尝试加密用密钥腌制的字符串.上面的代码是我之前用来实现的.我需要在React-Native中进行类似的操作.

当尝试使用crypto-browserify(我认为它可以在React-Native中工作)时,我在打包器中得到以下内容

Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/plist-parser/node_modules/sax/lib/sax.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/plist-parser/node_modules/sax/lib/sax.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/create-hash/node_modules/cipher-base/index.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/create-hash/node_modules/cipher-base/index.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/create-hmac/browser.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-cipher/node_modules/browserify-aes/node_modules/cipher-base/index.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-cipher/node_modules/browserify-aes/node_modules/cipher-base/index.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-cipher/node_modules/browserify-des/node_modules/cipher-base/index.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-cipher/node_modules/browserify-des/node_modules/cipher-base/index.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/browser.js
Unable to resolve module vm from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/api.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/base/buffer.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/decoders/pem.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/encoders/der.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/encoders/pem.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/browserify-aes/node_modules/cipher-base/index.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/parse-asn1/node_modules/browserify-aes/node_modules/cipher-base/index.js
Unable to resolve module vm from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/api.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/base/buffer.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/decoders/pem.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/encoders/der.js
Unable to resolve module buffer from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/asn1.js/lib/asn1/encoders/pem.js
Unable to resolve module stream from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/browserify-aes/node_modules/cipher-base/index.js
Unable to resolve module string_decoder from /Users/kelseyregan/BitBucket/React-Native-core/reup/node_modules/crypto-browserify/node_modules/public-encrypt/node_modules/parse-asn1/node_modules/browserify-aes/node_modules/cipher-base/index.js
正如Nader Dabit指出的那样,在版本0.12.0上使用带有RN的npm包crypto-js似乎可以解决问题.
原文链接:https://www.f2er.com/react/301022.html

猜你在找的React相关文章