React-Native + crypto: как генерировать HMAC в React-Native?

Я пробовал криптографию, которая, очевидно, не работает, потому что она зависит от работы узла. Итак, я обратился к 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

1 ответов


Как отметил Надер Дабит, использование пакета npm crypto-js с RN в версии 0.12.0, похоже, делает трюк.