junkurihara / jscu Goto Github PK
View Code? Open in Web Editor NEWJavaScript cryptographic utilities for crypto-suite compatibility including PEM/X509/JWK converter.
Home Page: https://junkurihara.github.io/jscu-webpage/
License: MIT License
JavaScript cryptographic utilities for crypto-suite compatibility including PEM/X509/JWK converter.
Home Page: https://junkurihara.github.io/jscu-webpage/
License: MIT License
when i use this library in a service worker, it will try to use node's crypto library as defined in https://github.com/junkurihara/jscu/blob/develop/packages/js-crypto-env/src/index.ts
however the problem with this is, that in a service worker window is not defined and it needs crypto.subtle instead of window.crypto.subtle
i thought about a way to fix this and came up with either checking for only crypto (or crypto.subtle) instead of the window and window.crypto in js-crypto-env so it doesn't mistake the service worker for a nodejs environment, or you could simply allow the crypto interface to be also user-defined, since the decrypt/encrypt functions in webapi actually pass it as a variable
jscu/packages/js-crypto-aes/src/aes.ts
Lines 79 to 97 in 6a881aa
jscu/packages/js-crypto-aes/src/webapi.ts
Lines 115 to 135 in 6a881aa
hello, this project is interesting to me, because the thing holding me back from switching from node to deno, has been deno's current lack of complete crypto implementation, which my production apps require
are there plans for this project to support deno?
cheers! ๐ป
Hi @junkurihara , while running the code locally it works fine.
But while using in aws with centos os getting below error,
core.mjs:6469 ERROR Error: Uncaught (in promise): Error: UnsupportedEnvironment
Error: UnsupportedEnvironment
at eval (aes.js:159:23)
at step (aes.js:55:23)
at Object.eval [as next] (aes.js:36:53)
at eval (aes.js:30:71)
at new ZoneAwarePromise (zone.js:1340:1)
at __awaiter (aes.js:26:12)
at Object.decrypt (aes.js:142:12)
at _callee2$ (rum.js:99:77)
at tryCatch (runtime.js:63:40)
at Generator.invoke [as _invoke] (runtime.js:293:22)
at resolvePromise (zone.js:1255:1)
at zone.js:1162:1
at asyncGeneratorStep (asyncToGenerator.js:10:5)
at _throw (asyncToGenerator.js:33:9)
at ZoneDelegate.invoke (zone.js:400:1)
at Object.onInvoke (core.mjs:25450:1)
at ZoneDelegate.invoke (zone.js:399:1)
at Zone.run (zone.js:160:1)
at zone.js:1318:1
Thanks!
There is babel plugin in js-x509-utils deps list. I think it should be in devDependencies:
https://github.com/junkurihara/jscu/blob/develop/packages/js-x509-utils/package.json#L40
Hi @junkurihara,
In relation to #548, can you elaborate? Trying to import js-crypto-key-utils results in a failure about missing crypto, which is obviously not present on react-native.
hey,
I want to implement this in react native to encrypt data and send to nodejs backend.
did it supports both.
Hey guys,
Now I think to remove ugly branches that have been implemented in order to support legacy IE 11. I would like to hear your opinions about this change.
I know that most jscu users and developers use Chromium/Safari/Firefox based browsers and there's just few IE users. Further, in order to support IE11, I had added tons of extra ugly codes. So I would like to discontinue the support of IE11, and this yields smaller bundled-js size and simpler codes. When I suspend IE codes, I would also like to bump the jscu version to 1.0.0.
Cheers!
I have the following code. I need to extract subject field from CA certificate to use it as issuer in newly created certificate. I understand it is stored in tbsCertificate with asn1 encoding.
Is it possible to get this data without using some other external module (i.e. asn1.js and so on)?
const CA_crt_pem= fs.readFileSync(CaPath + '/rootCA.pem').toString()
const CA_crt_jwk= jscu.x509.parse(CA_crt_pem, 'pem')
console.log(CA_crt_jwk)
Output:
{
tbsCertificate: Uint8Array [
48, 130, 1, 139, 160, 3, 2, 1, 2, 2, 20, 27,
46, 168, 145, 223, 170, 96, 29, 156, 82, 142, 209, 121,
82, 142, 81, 196, 237, 109, 144, 48, 10, 6, 8, 42,
134, 72, 206, 61, 4, 3, 2, 48, 72, 49, 11, 48,
9, 6, 3, 85, 4, 6, 19, 2, 82, 85, 49, 20,
48, 18, 6, 3, 85, 4, 8, 12, 11, 75, 97, 108,
105, 110, 105, 110, 103, 114, 97, 100, 49, 22, 48, 20,
6, 3, 85, 4, 10, 12, 13, 66, 101, 101, 114, 119,
97, 114, 101, 32,
... 299 more items
],
signatureValue: Uint8Array [
48, 70, 2, 33, 0, 236, 115, 244, 225, 39, 79, 168,
212, 18, 172, 215, 214, 194, 102, 125, 187, 123, 242, 88,
43, 174, 16, 39, 14, 177, 61, 177, 88, 104, 33, 156,
118, 2, 33, 0, 192, 101, 44, 129, 246, 236, 235, 219,
87, 142, 248, 242, 92, 8, 227, 79, 216, 6, 197, 247,
89, 60, 125, 108, 247, 131, 66, 242, 62, 62, 59, 230
],
signatureAlgorithm: { algorithm: 'ecdsa-with-sha256', parameters: { hash: 'SHA-256' } }
}
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
Is it possible to output the contents of a certificate, similar like the output from openssl:
openssl x509 -in server.pem -noout -text
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 4096 (0x1000)
Signature Algorithm: sha256WithRSAEncryption
Issuer: C = GB, ST = England, O = Alice Ltd, OU = Alice Ltd Certificate Authority, CN = Alice Ltd Intermediate CA
Validity
Not Before: Apr 30 22:32:26 2020 GMT
Not After : May 10 22:32:26 2021 GMT
Subject: C = US, ST = Califonia, L = Mountain View, O = Alice Ltd, OU = Alice Ltd Web Services, CN = localhost
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public-Key: (2048 bit)
...
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/ci-test.yml
actions/checkout v4
actions/setup-node v4
actions/cache v4
codecov/codecov-action v4
actions/checkout v4
actions/setup-node v4
actions/checkout v4
actions/setup-node v4
package.json
@types/elliptic 6.4.18
@types/jest 29.5.12
@types/node 20.14.2
@typescript-eslint/eslint-plugin 7.12.0
@typescript-eslint/parser 7.12.0
can-npm-publish 1.3.6
cross-env 7.0.3
esdoc 1.1.0
esdoc-standard-plugin 1.0.0
eslint 9.4.0
jasmine-core 5.1.2
jest 29.7.0
karma 6.4.3
karma-chrome-launcher 3.2.0
karma-cli 2.0.0
karma-jasmine 5.1.0
karma-typescript 5.5.4
lerna 8.1.3
ts-jest 29.1.4
ts-loader 9.5.1
typescript 5.2.2
webpack 5.91.0
webpack-cli 5.1.4
packages/js-crypto-aes/package.json
js-encoding-utils 0.7.3
packages/js-crypto-ec/package.json
asn1.js ~5.4.1
buffer ~6.0.0
elliptic ~6.5.0
js-encoding-utils 0.7.3
@types/elliptic 6.4.18
packages/js-crypto-env/package.json
packages/js-crypto-hash/package.json
buffer ~6.0.0
hash.js ~1.1.7
md5 ~2.3.0
sha3 ~2.1.0
js-encoding-utils 0.7.3
packages/js-crypto-hkdf/package.json
js-encoding-utils 0.7.3
packages/js-crypto-hmac/package.json
js-encoding-utils 0.7.3
packages/js-crypto-key-utils/package.json
asn1.js ~5.4.1
buffer ~6.0.0
des.js ~1.1.0
elliptic ~6.5.0
js-encoding-utils 0.7.3
lodash.clonedeep ~4.5.0
packages/js-crypto-pbkdf/package.json
js-encoding-utils 0.7.3
packages/js-crypto-random/package.json
packages/js-crypto-rsa/package.json
bn.js ~5.2.0
buffer ~6.0.0
js-encoding-utils 0.7.3
packages/js-crypto-utils/package.json
js-encoding-utils 0.7.3
lodash.clonedeep ~4.5.0
packages/js-x509-utils/package.json
asn1.js ~5.4.1
asn1.js-rfc5280 ~3.0.0
bn.js ~5.2.0
buffer ~6.0.0
js-encoding-utils 0.7.3
โ js-crypto-rsa yarn build
yarn run v1.22.5
$ rm -rf ./dist && yarn babel && yarn webpack:prod
$ cross-env NODE_ENV=production tsc --build ./tsconfig.json
src/oaep.ts:5:21 - error TS2307: Cannot find module 'js-crypto-hash' or its corresponding type declarations.
5 import jschash from 'js-crypto-hash';
~~~~~~~~~~~~~~~~
src/oaep.ts:6:20 - error TS2307: Cannot find module 'js-crypto-random' or its corresponding type declarations.
6 import random from 'js-crypto-random';
~~~~~~~~~~~~~~~~~~
src/oaep.ts:119:33 - error TS7006: Parameter 'elem' implicitly has an 'any' type.
119 const maskedSeed = seed.map( (elem, idx) => 0xFF & (elem ^ seedMask[idx]));
~~~~
src/oaep.ts:119:39 - error TS7006: Parameter 'idx' implicitly has an 'any' type.
119 const maskedSeed = seed.map( (elem, idx) => 0xFF & (elem ^ seedMask[idx]));
~~~
src/nodeapi.ts:6:19 - error TS2307: Cannot find module 'js-crypto-key-utils' or its corresponding type declarations.
6 import {Key} from 'js-crypto-key-utils';
~~~~~~~~~~~~~~~~~~~~~
src/rsa.ts:5:23 - error TS2307: Cannot find module 'js-crypto-env' or its corresponding type declarations.
5 import * as util from 'js-crypto-env';
~~~~~~~~~~~~~~~
Found 6 errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Currently, jscu
uses Lerna (+ Yarn workspace) to manage this monorepo structure. However, as you may know, Lerna is not being actively maintained and almost outdated. So I think we should consider to switch our monorepo management tool from Lerna to another one before we faces an issue due to the outdated tool.
So if you have any idea of alternatives to Lerna suitable for this monorepo, please please let us know!
DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
The cert I have created with code:
const name = {
countryName: 'US',
stateOrProvinceName: 'D',
organizationName: 'D',
organizationalUnitName: 'D',
commonName: 'D'
}
jscu.x509.fromJwk(
keyPair.publicKey._jwk, // Client public key (derived from private)
privateCAKeyJwk, // CA private key (for signature)
'pem',
{
signature: 'ecdsa-with-sha256', // signature algorithm
days: 365, // expired in days
issuer: name,
subject: name
}
).then( async (cert) => {
console.log(cert)
}
has failed verication. You can see that something strange with Issuer and Subject fields (separators changed)
openssl verify -CAfile ./rootCA.pem ./Output/brwr-00000002/device.crt
C = US + ST = D + O = D + OU = D + CN = D
error 18 at 0 depth lookup: self signed certificate
error ./Output/brwr-00000002/device.crt: verification failed
openssl x509 -in ./Output/brwr-00000002/device.crt -text
Certificate:
Data:
Version: 1 (0x0)
Serial Number:
27:5d:44:9a:fe:dc:0b:0e:a1:39:1b:b7:03:76:81:a9:93:a9:a8:01
Signature Algorithm: ecdsa-with-SHA256
Issuer: C = US + ST = D + O = D + OU = D + CN = D
Validity
Not Before: Jan 13 22:08:14 2020 GMT
Not After : Jan 12 22:08:14 2021 GMT
Subject: C = US + ST = D + O = D + OU = D + CN = D
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:5d:34:d7:5e:05:53:49:81:b6:4a:31:85:4f:d0:
f1:b1:85:1f:f9:c2:89:03:b2:de:a8:0f:d8:b6:eb:
b4:48:6a:fc:0f:a9:f1:96:5b:19:24:63:84:06:7f:
3b:d9:5f:db:03:52:13:19:18:a4:77:6a:11:64:46:
c8:0e:85:f5:6b
ASN1 OID: prime256v1
NIST CURVE: P-256
Signature Algorithm: ecdsa-with-SHA256
30:45:02:21:00:ad:30:47:2d:72:52:bb:2d:87:e3:08:2c:00:
d8:cf:f5:f4:26:1d:4b:d7:dd:55:8f:86:4d:aa:3f:89:29:a3:
fc:02:20:3d:50:da:ec:e7:73:87:b5:49:e0:34:ba:f6:cd:9e:
e2:30:09:a8:83:93:64:26:e0:a6:ca:96:c1:29:ff:ca:2d
-----BEGIN CERTIFICATE-----
MIIBaTCCAQ0CFCddRJr+3AsOoTkbtwN2gamTqagBMAwGCCqGSM49BAMCBQAwNTEz
MAkGA1UEBgwCVVMwCAYDVQQIDAFEMAgGA1UECgwBRDAIBgNVBAsMAUQwCAYDVQQD
DAFEMB4XDTIwMDExMzIyMDgxNFoXDTIxMDExMjIyMDgxNFowNTEzMAkGA1UEBgwC
VVMwCAYDVQQIDAFEMAgGA1UECgwBRDAIBgNVBAsMAUQwCAYDVQQDDAFEMFkwEwYH
KoZIzj0CAQYIKoZIzj0DAQcDQgAEXTTXXgVTSYG2SjGFT9DxsYUf+cKJA7LeqA/Y
tuu0SGr8D6nxllsZJGOEBn872V/bA1ITGRikd2oRZEbIDoX1azAMBggqhkjOPQQD
AgUAA0gAMEUCIQCtMEctclK7LYfjCCwA2M/19CYdS9fdVY+GTao/iSmj/AIgPVDa
7Odzh7VJ4DS69s2e4jAJqIOTZCbgpsqWwSn/yi0=
-----END CERTIFICATE-----
But if I use openssl to create x509 with previously created (in jscu) private key - this certificate seems to be correct:
openssl verify -CAfile ./rootCA.pem ./Output/brwr-00000002/device.crt
./Output/brwr-00000002/device.crt: OK
Hello!
I have installed your library per npm. I import it with 'import rsa from "js-crypto-rsa"' (in my case i have only installed the rsa part). If i start my react app with npm start the follow error appear:
If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }' - install 'crypto-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "crypto": false }
Can you help?
Greatings, Flo
There are great complications faced as the architecture is not in typescript, and hence a step towards improving it must be taken !!
Please add 'emailAddress' attribute and OID to
attributeTypeOIDMap (./node_modules/js-x509-utils/dist/x509.js:240)
var attributeTypeOIDMap = {
// X509name DirectoryName
name: [2, 5, 4, 41],
surname: [2, 5, 4, 4],
givenName: [2, 5, 4, 42],
initials: [2, 5, 4, 43],
generationQualifier: [2, 5, 4, 44],
commonName: [2, 5, 4, 3],
localityName: [2, 5, 4, 7],
stateOrProvinceName: [2, 5, 4, 8],
organizationName: [2, 5, 4, 10],
organizationalUnitName: [2, 5, 4, 11],
title: [2, 5, 4, 12],
dnQualifier: [2, 5, 4, 46],
countryName: [2, 5, 4, 6],
serialNumber: [2, 5, 4, 5],
pseudonym: [2, 5, 4, 65],
domainComponent: [0, 9, 2342, 19200300, 100, 1, 25],
emailAddress: [1, 2, 840, 113549, 1, 9, 1],
};
I am getting an error when converting an elliptic curve DER to JWK. I have been able to convert this same key in swift and java.
Error: FailedToDecodeKey
The code
const publicKeyObject = new jscu.Key('der', new Uint8Array(Buffer.from(key, 'base64')));
const key = await publicKeyObject.export('jwk');
The DER
MIICnDCCAkKgAwIBAgIIJr8oA/3jYAQwCgYIKoZIzj0EAwIwUDEkMCIGA1UEAwwbUG9sYW5kIERHQyBSb290Q1NDQSAxIEFDQyBTMRswGQYDVQQKDBJNaW5pc3RyeSBvZiBIZWFsdGgxCzAJBgNVBAYTAlBMMB4XDTIxMDUyNDExMTgxNloXDTIzMDUyNDExMTgxNlowcjEtMCsGA1UEAwwkUG9sYW5kIFZhY2NpbmF0aW9uIERHQyBTZXJ2aWNlIDMgQUNDMRcwFQYDVQQLDA5lSGVhbHRoIENlbnRlcjEbMBkGA1UECgwSTWluaXN0cnkgb2YgSGVhbHRoMQswCQYDVQQGEwJQTDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABBb5V0Rbo5Qc1yAVxRyXaLt/QjmI4WG3qsXf81WoH6L2Uf4oj5iGnAuem1TSotax+FUgvn+GbcUg7BTrL+ePAQSjgeMwgeAwHwYDVR0jBBgwFoAUqc15HwkAJgfQl/0DpjHxRVJ9E28wFgYDVR0lBA8wDQYLKwYBBAGON49lAQIwTAYDVR0fBEUwQzBBoD+gPYY7aHR0cDovL2FjYy1wMS5lemRyb3dpZS5nb3YucGwvY2NwMS9jcmwvREdDUm9vdENTQ0ExQUNDUy5jcmwwHQYDVR0OBBYEFAenLsHAhybxn8MjzWYLq+xrD8iYMCsGA1UdEAQkMCKADzIwMjEwNTI0MTExODE2WoEPMjAyMjA1MjQxMTE4MTZaMAsGA1UdDwQEAwIHgDAKBggqhkjOPQQDAgNIADBFAiEAw17oXs3K8q+VorcGq014/zCZAnxqRIQ6fCkHGCENJWQCIB3hvpk+NdLphX7aokerbhsF6xuJ7hT6DnD67SFgLI/9
Can js-crypto-key-utils be used to set a Uint8Array with the structure of a jwk object
Something like this
Uint8Array(32)ย [217, 75, 191, 175, 56, 204, 195, 184, 100, 8, 111, 246, 165, 76, 251, 227, 86, 250, 37, 57, 35, 62, 191, 131, 221, 73, 44, 115, 107, 105, 153, 240]
to
KCVXrFs8oJBheco-JxbHkPL9bxyN5\WZ68hyfVgrBuJg
Hello guys,
I actually got stacked up to migrate jscu to brand-new Webpack 5.x. It has incredibly lots of breaking changes... Actually it works with Webpack 4.x flawlessly, however, it should be migrated to 5.x for future compatibility and support. Anyone can help it? Please!
Jun
const rsa = require('js-crypto-rsa')
const msg = Uint8Array.from([
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
])
rsa.generateKey(2048).then(key => {
const publicKey = key.publicKey
const privateKey = key.privateKey
rsa.encrypt(msg, publicKey, 'SHA-256', {name: 'RSA-PSS'})
.then(encrypted => {
console.log(encrypted)
return rsa.decrypt(encrypted, privateKey, 'SHA-256', {name: 'RSA-PSS'})
})
.then(decrypted => {
console.log(decrypted)
})
})
=>
(node:12827) UnhandledPromiseRejectionWarning: Error: MessageTooLong
The headings are misplaced. First set of code corresponds to one without salt and second corresponds to one with salt.
also isn't it hkdf.compute.....
instead of hmac.compute...
hmac.compute(masterSecret, hash, length, info, salt).then( (derivedKey) => {
// now you get a key derived from the masterSecret
});
I want use it to generate sha3-256 hash, what should i do?below is realization of the package futoin-hkdf
const hkdf = new Hkdf.Hkdf('sha3-256');
const masterPrk =hkdf.extract('aaa', 'bbb');
const secretKey =hkdf.expand(masterPrk, 'ccc', 32);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.