React-Native + crypto : How to generate HMAC in React-Native? - cryptography

I have tried crypto, which obviously doesn't work because it depends on node running. So, I turned to crypto-browserify, but I believe there are dependency issues. If anyone could help, I'd be much appreciative.
For reference, I previously used crypto like so:
crypto.createHmac('md5', "MY_KEY").update('SOMETHING_TO_ENCRYPT').digest('hex');
EDIT
I am trying to encrypt a string salted with a key. The above code is what I used previously to attain this. I need to do an analogous operation in React-Native.
When trying to use crypto-browserify (which I thought would work in React-Native), I get the following in the packager:
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

As Nader Dabit pointed out, using the npm package crypto-js with RN on version 0.12.0 seems to do the trick.

For the year of 2020, you should use crypto-js with v3.3.0 now.

Related

client feature:install fcrepo-service-activemq

I'm trying to Install Karaf Features on Ubuntu 20.04 using the code below.
/opt/karaf/bin/client feature:install fcrepo-service-activemq
And I am getting the message error below:
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=fcrepo-service-activemq; type=karaf.feature; version="[5.0.0,5.0.0]"; filter:="(&(osgi.identity=fcrepo-service-activemq)(type=karaf.feature)(version>=5.0.0)(version<=5.0.0))" [caused by: Unable to resolve fcrepo-service-activemq/5.0.0: missing requirement [fcrepo-service-activemq/5.0.0] osgi.identity; osgi.identity=activemq-camel; type=karaf.feature; version="[5.14.0,6.0.0)" [caused by: Unable to resolve activemq-camel/5.15.11: missing requirement [activemq-camel/5.15.11] osgi.identity; osgi.identity=org.apache.activemq.activemq-camel; type=osgi.bundle; version="[5.15.11,5.15.11]"; resolution:=mandatory [caused by: Unable to resolve org.apache.activemq.activemq-camel/5.15.11: missing requirement [org.apache.activemq.activemq-camel/5.15.11] osgi.wiring.package; filter:="(&(osgi.wiring.package=org.springframework.jms.connection)(version>=4.0.0)(!(version>=6.0.0)))"]]]
What should I do to install this feature successfully without any error message?
Servus,
Installation notes created by my predecessor show that before command
features:install
I should add a repository, that is
features:addurl
which adds a symbolic repository based on a file stored at
.../etc/org.ops4j.pax.url.mvn.cfg
Maybe this is the issue here.

Could not resolve co.touchlab:kermit

I've been working on a Kotlin Multiplatform library for a while now and I started using kermit logger for it. Everything builds well the only concern I have are the following warnings I am getting
Unable to resolve dependency for ':#debug/compileClasspath': Could not resolve co.touchlab:kermit:1.0.2.
Show Details
Affected Modules: AddressLibrary
Unable to resolve dependency for ':#debugUnitTest/compileClasspath': Could not resolve co.touchlab:kermit:1.0.2.
Show Details
Affected Modules: AddressLibrary
Unable to resolve dependency for ':#debugAndroidTest/compileClasspath': Could not resolve co.touchlab:kermit:1.0.2.
Show Details
Affected Modules: AddressLibrary
How can I make these go away?

Eclipse launch error shows org.osgi.framework.BundleException

I have the following error during my generator development.
I tried several times to refresh my workspace but it'd not worked.
org.osgi.framework.BundleException: Could not resolve module:
org.artop.ecuc.gautosar.accessors.check [72]
org.osgi.framework.BundleException: Could not resolve module:
org.eclipse.emf.mwe2.language [123]
org.osgi.framework.BundleException: Could not resolve module:
org.eclipse.sphinx.emf.check [151]
org.osgi.framework.BundleException: Could not resolve module:
org.eclipse.sphinx.emf.mwe.dynamic [152]
org.osgi.framework.BundleException: Could not resolve module:
org.eclipse.xtend.core [168]
org.osgi.framework.BundleException: Could not resolve module: org.eclipse.xtext.common.types [173]
org.osgi.framework.BundleException: Could not resolve module:
org.eclipse.xtext.xbase.testing
The messages were not meaningful enough for me to resolve the issue.
It looked like it was the version problem.
Anyone can help?
I checked throughout all plugins and I believed that they have been installed.
If your Eclipse environment doesn't have these kinds of plugins installed, you should check for installation.
In my case, the problem had come from my workspace.
I wiped out all data and make it again.
And after the new workspace finished to build, my application worked well. I think due to run-time exception of javaw (JRE), some plugins were broken, but just my guess.

Import fritzapi (node package) into Ionic project

I am currently trying to use this API in my Ionic project, but man, I have no clue on how to do it. I tried figuring it out using things like this, but I always get errors on ionic server:
101 unchanged chunks
[ng] chunk {home-home-module} home-home-module.js, home-home-module.js.map (home-home-module) 3.07 MB [rendered]
[ng]
[ng] ERROR in ./node_modules/request/lib/har.js
[ng] Module not found: Error: Can't resolve 'fs' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\request\lib'
[ng] ERROR in ./node_modules/forever-agent/index.js
[ng] Module not found: Error: Can't resolve 'net' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\forever-agent'
[ng] ERROR in ./node_modules/tough-cookie/lib/cookie.js
[ng] Module not found: Error: Can't resolve 'net' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\tough-cookie\lib'
[ng] ERROR in ./node_modules/tunnel-agent/index.js
[ng] Module not found: Error: Can't resolve 'net' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\tunnel-agent'
[ng] ERROR in ./node_modules/forever-agent/index.js
[ng] Module not found: Error: Can't resolve 'tls' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\forever-agent'
[ng] ERROR in ./node_modules/tunnel-agent/index.js
[ng] Module not found: Error: Can't resolve 'tls' in 'D:\Programmierung\Workspaces\Ionic\HomeAutomation\node_modules\tunnel-agent'
[ng] Time: 2321ms
[ng] i 「wdm」: Failed to compile.
I'm super new to webdev and Ionic in general, so I don't know if this is even possible, but I feel like it should be. Above error is a result of the following code:
import { Component } from '#angular/core';
import * as fritzapi from 'fritzapi';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor() {
fritzapi.getSessionID("removedforstack", "removedforstack").then(function(sid) {
console.log(sid);
});
}
}
Thanks in advance to everyone who's trying to help <3
I suspect this isn't possible. I think that you are trying to use something that's expected to be run on the local network in a node environment.
I did a search and found this article:
https://www.amadousall.com/angular-cli-module-not-found-error-cant-resolve/
Which say they used to do this:
supply an empty module when fs, crypto, tls and net were requested.
Which doesn't make sense really out of context but I couldn't find a simple bit to quote, take a look at the article.
Ultimately the angular team says:
Browser code should not rely on things that are not available in browser environments.
I'm assuming that the library needs to use these things to connect to the local network and interact with your home automation.
If i'm wrong then the article does have a way to supply an empty file instead of those modules, so if the code has alternate modes then it could work, but it doesn't seem likely to me off the top of my head.

google-translate-api giving an error in react-native

while importing google-translate-api on my React Native app, I'm getting an error "couldn't resolve the module querystring".
Please find the attached screenshot.
Error
Error:
Unable to resolve module "querystring" from "...". Module "querystring" does not exist in the Haste module map.