webcrypto | A WebCrypto Polyfill for NodeJS | Cryptography library
kandi X-RAY | webcrypto Summary
kandi X-RAY | webcrypto Summary
We wanted to be able to write Javascript that used crypto on both the client and the server but we did not want to rely on Javascript implementations of crypto. The only native cryptography available in browser is Web Crypto, this resulted in us creating a @peculiar/webcrypto.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of webcrypto
webcrypto Key Features
webcrypto Examples and Code Snippets
Community Discussions
Trending Discussions on webcrypto
QUESTION
I have an encrypted private RSA key:
...ANSWER
Answered 2022-Feb-06 at 13:38So for anyone who will in the future maybe face the same issue like I did:
PKI.js is providing an examples folder in their repo: OpenSSLPrivateKeyEncryption
In there you will find a method called decrypt. With the code I were able to decrypt my AES-CBC Private key.
QUESTION
I have a ReactJS application that should be able to verify signatures with a given RSA public key like the Web Crypto API it does with subtle and import_key etc. Does any one knows if there exist such a library or how to use the Web Crypto API in react directly? I searched a lot, but I wasn't able to find a working example for me. Maybe I missed something.
I tried before the @trust/webcrypto library and installed it with npm.
This is the code that I tried before:
...ANSWER
Answered 2022-Jan-07 at 06:42@Topaco mentioned to use a public key I has to use the spki
format. That solves the issue with the import of the public key.
This code solves my problem.
QUESTION
I'm currently encrypting data in PHP as follows:
...ANSWER
Answered 2021-Dec-23 at 04:35PKCS#1 Versus PKCS#8
Note that while private keys generated without pass phrases in PHP are PKCS#1, the private key generated from PHP with a pass phrase is actually PKCS#8 (see this link for how to determine which standard applies to a private key).
Third Party Library Required
In order to work with PEM-format keys, a custom JavaScript library (or other custom code) is required. There are various libraries at this link which you can look at. Many are not maintained anymore.
This example uses the Forge JavaScript library, but you could also use a different library.
Installing/Importing Forge
While there are various ways to build the Forge environment, the easiest is to add the following HTML code prior to where you need to do encryption/decryption:
QUESTION
Ok, so I was building an application and using RSA to decrypt data encrypted from the browser's webcrypto and I was getting a strange error before the web side even started.. I tried searching the error but I didn't find anything helpful.. I'm using nodejs(v16.10.0
)
ANSWER
Answered 2021-Oct-06 at 14:21This is due to your atob()
and btoa()
methods defined for NodeJS.
Buffer.from()
and Buffer#toString()
apply UTF-8 by default if no other encoding is specified. However, UTF-8 generally corrupts arbitrary binary data. Instead of UTF-8 use binary
as encoding:
QUESTION
When I try to run an application that uses node-webcrypto-ossl
node module I get the error:
ANSWER
Answered 2021-Oct-04 at 23:09Obviously node-webcrypto-ossl requires an older version of glibc.
No. GLIBC is backwards compatible: applications built against older version continue to run fine on newer GLIBC versions.
Your problem is the opposite: you have an application linked against GLIBC_2.32
trying to run against an older version of GLIBC.
The version of glibc installed on my machine is 2.33-5
The application is not using that version; it's using some other GLIBC.
The problem was that I was trying to run my app in docker ...
That's one way running against older than expected GLIBC could happen.
QUESTION
I am struggling to understand how to use the npm jose module (https://www.npmjs.com/package/jose) to create and verify signed JWT tokens in my Node application. My scenario is this: I want to sign an authenticated request to access a resource. I can successfully create a JWT claim for this request grant token that respects the properties of “its” and “aud”, “exp”, etc. but I want to sign it (to wit, using the SignJWT object and the ‘sign’ method) so that when it gets passed back to my server as a request I can validate it and grant or reject access. The “sign” method doesn’t seem to like anything I pass it for the ‘key’ parameter (I am not passing any options — maybe I should be, but what?). I am attempting to use RSA key pairs. I want to sign with the private key and verify with the public key. For my immediate need, I suppose I could use a symmetric key instead, but I am thinking of some other future scenarios where I will want this classic PKCS relationship of certificate keys. And at any rate, I don’t think this choice has anything to do with the current roadblock to my progress. I first tried to use jose/util/generate_key_pair to create my public/private pair. But when I went to use the key, the error informed me this was not supported by my implementation. So I switched to trying to create a ‘pem’ cert outside of my app and applying that (as text), but that also failed. The ‘sign’ method reports that the key must be a ‘KeyLike’, ‘CryptoKey’, or ‘Uint8Array’ type. Well, the UInt8Array (node buffer) is not enough type information: it doesn’t speak to what is in that buffer, and “KeyLike” is such a vague definition that it’s ignorable. After beseeching the oracles of the search engines, I found I could create a key pair in CryptoKey format using the following from Node APIs:
...ANSWER
Answered 2021-Sep-11 at 05:13I have also struggled with signing and verifying JWT using jose
but was finally able to succeed with HS256 symmetric key encryption. I produced it by following steps (I am using jose-node-cjs-runtime
for Node.js only use case. Feel free to replace with desired package. Also please note that I have found that these codes are working for Node.js version 16.7.0, 16.9.0 so please ensure that any of them is installed. If you want to deploy these changes to production environment, then also you have to ensure the deploy environment has the same Node.js version. One way this can be achieved is by mentioning Node.js version in engines
key in package.json
):
QUESTION
I am using a Javascript to generate wireguard keypairs but it's browser faced so i removed the window objects and have one more issue that prevents creation of private key.
the issue is this line of code that i cannot run in nodejs:
...ANSWER
Answered 2021-Sep-07 at 15:25You need to understand getRandomValues
is on window.crypto
that means it works on browser. To make it work on Node.js
you need to install get-random-values
QUESTION
I am playing around with presigned urls. Server generates a presigned url using node, works great with object storage. Now I am trying to verify the presigned url with a Cloudflare worker, but I don't get it.
Any solutions on the worker side for this server code?
...ANSWER
Answered 2021-Aug-28 at 13:55The JavaScript runtime of Cloudflare Workers is not based on Node. So there won't be a pre-bundled module called crypto
that you can require or import.
If you start from these template projects with Webpack configured, required/imported modules are typically those which you have installed manually (e.g. via npm install/yarn add foobar
and later being listed as dependencies in package.json
). In other words, it is somewhat alike to writing front-end JS.
The Workers provides a built-in WebCrypto-compliant cryptography library implementation as documented here: https://developers.cloudflare.com/workers/runtime-apis/web-crypto. According to the doc, crypto
is just a global object that can be accessed directly with importing.
Even though I do not have a try, I suppose the link to the example you given is a completed Worker script with no more modifications needed to test. That is, just copy&paste into the online editor of Workers and test.
QUESTION
I am trying to verify an ECDSA signature via WebCrypto and failing. The signature is created using Java (Bouncy Castle). The curve used is secp256r1 and SHA256 hash is used at signature creation. Then I tried creating signature using RSA (SHA256) in Java and tried verified in WebCrypto and succeeded. This seems like an ECDSA specific issue. In java I exported the public key in SPKI and then imported successfully in WebCrypto. What could be causing WebCrypto to fail verifying ECDSA based keys.
...ANSWER
Answered 2021-Aug-13 at 10:57EC signatures can be specified in two formats: r|s (IEEE P1363) or ASN.1/DER. Both formats are explained here.
WebCrypto uses the r|s format, while MEUCI...
has the ASN.1 format. Your signature in r|s format is Base64 encoded:
QUESTION
Python Code that works fine and I checked this Python code for message "a" it gives me the result "52F17E7031982DE1744A57F6EE9BD3A3"
...ANSWER
Answered 2021-Jun-26 at 15:37WebCrypto implicitly generates the hash of the data during signing using the digest SHA-256 specified in the key, so explicit hashing with SHA-256 is not necessary.
Also, the generated signature is directly hashed with MD5, i.e. without prior Base64 encoding.
With these changes, the JavaScript code is (using a test key):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install webcrypto
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page