Socket
Socket
Sign inDemoInstall

@trust/webcrypto

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trust/webcrypto - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

src/algorithms/AES-GCM.js

2

package.json
{
"name": "@trust/webcrypto",
"version": "0.2.1",
"version": "0.3.0",
"description": "WebCrypto API for Node.js",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -44,2 +44,9 @@ # W3C Web Cryptography API _(@trust/webcrypto)_

`@trust/webcrypto` requires recent versions of [node][node] and [npm][npm] to run. For key generation operations, it also requires [OpenSSL][openssl] to be installed on the system.
[node]: https://nodejs.org
[npm]: https://www.npmjs.com/
[openssl]: https://www.openssl.org/
```bash

@@ -82,3 +89,3 @@ $ npm install @trust/webcrypto --save

|AES-CBC | ✔ | ✔ | | | | ✔ | | | ✔ | ✔ | _ | _ |
|AES-GCM | _ | _ | | | | _ | | | _ | _ | _ | _ |
|AES-GCM | ✔ | ✔ | | | | ✔ | | | ✔ | ✔ | _ | _ |
|AES-KW | | | | | | _ | | | _ | _ | _ | _ |

@@ -108,8 +115,8 @@ |HMAC | | | ✔ | ✔ | | ✔ | | | ✔ | ✔ | | |

* please file [issues](https://github.com/anvilresearch/webcrypto/issues) :)
* for bug reports, include relevant details such as platform, version, relevant data, and stack traces
* be sure to check for existing issues before opening new ones
* read the documentation before asking questions
* it's strongly recommended to open an issue before hacking and submitting a PR
* we reserve the right to close an issue for excessive bikeshedding
* Please file [issues](https://github.com/anvilresearch/webcrypto/issues) :)
* When writing a bug report, include relevant details such as platform, version, relevant data, and stack traces
* Ensure to check for existing issues before opening new ones
* Read the documentation before asking questions
* It is strongly recommended to open an issue before hacking and submitting a PR
* We reserve the right to close an issue for excessive bikeshedding

@@ -120,11 +127,11 @@ ### Pull requests

* we're not presently accepting *unsolicited* pull requests
* create an issue to discuss proposed features before submitting a pull request
* create an issue to propose changes of code style or introduce new tooling
* ensure your work is harmonious with the overall direction of the project
* ensure your work does not duplicate existing effort
* keep the scope compact; avoid PRs with more than one feature or fix
* code review with maintainers is required before any merging of pull requests
* new code must respect the style guide and overall architecture of the project
* be prepared to defend your work
* We're not presently accepting *unsolicited* pull requests
* Create an issue to discuss proposed features before submitting a pull request
* Create an issue to propose changes of code style or introduce new tooling
* Ensure your work is harmonious with the overall direction of the project
* Ensure your work does not duplicate existing effort
* Keep the scope compact; avoid PRs with more than one feature or fix
* Code review with maintainers is required before any merging of pull requests
* New code must respect the style guide and overall architecture of the project
* Be prepared to defend your work

@@ -164,2 +171,4 @@ #### Style guide

* JC Bailey [@thelunararmy](https://github.com/thelunararmy)
* Loan Budea [@johnny90](https://github.com/johnny90)
* Abdulrahman Alotaibi [@adminq80](https://github.com/adminq80)

@@ -166,0 +175,0 @@ ## MIT License

@@ -166,4 +166,8 @@ /**

let publicKey = spawnSync('openssl', ['ec', '-pubout'], { input: privateKey }).stdout
keypair.privateKey = privateKey.toString('ascii').trim()
keypair.publicKey = publicKey.toString('ascii').trim()
try {
keypair.privateKey = privateKey.toString('ascii').trim()
keypair.publicKey = publicKey.toString('ascii').trim()
} catch(error){
throw new OperationError(error.message)
}
} catch (error) {

@@ -170,0 +174,0 @@ // 3. If any operation fails then throw error

@@ -17,3 +17,3 @@ /**

supportedAlgorithms.define('AES-CBC', 'encrypt', '../algorithms/AES-CBC')
//supportedAlgorithms.define('AES-GCM', 'encrypt', )
supportedAlgorithms.define('AES-GCM', 'encrypt', '../algorithms/AES-GCM')
//supportedAlgorithms.define('AES-CFB', 'encrypt', )

@@ -27,3 +27,3 @@

supportedAlgorithms.define('AES-CBC', 'decrypt', '../algorithms/AES-CBC')
//supportedAlgorithms.define('AES-GCM', 'decrypt', )
supportedAlgorithms.define('AES-GCM', 'decrypt', '../algorithms/AES-GCM')
//supportedAlgorithms.define('AES-CFB', 'decrypt', )

@@ -86,3 +86,3 @@

//supportedAlgorithms.define('AES-CMAC', 'generateKey', )
//supportedAlgorithms.define('AES-GCM', 'generateKey', )
supportedAlgorithms.define('AES-GCM', 'generateKey', '../algorithms/AES-GCM')
//supportedAlgorithms.define('AES-CFB', 'generateKey', )

@@ -105,3 +105,3 @@ //supportedAlgorithms.define('AES-KW', 'generateKey', )

//supportedAlgorithms.define('AES-CMAC', 'importKey', )
//supportedAlgorithms.define('AES-GCM', 'importKey', )
supportedAlgorithms.define('AES-GCM', 'importKey', '../algorithms/AES-GCM')
//supportedAlgorithms.define('AES-CFB', 'importKey', )

@@ -126,3 +126,3 @@ //supportedAlgorithms.define('AES-KW', 'importKey', )

//supportedAlgorithms.define('AES-CMAC', 'exportKey', )
//supportedAlgorithms.define('AES-GCM', 'exportKey', )
supportedAlgorithms.define('AES-GCM', 'exportKey', '../algorithms/AES-GCM')
//supportedAlgorithms.define('AES-CFB', 'exportKey', )

@@ -129,0 +129,0 @@ //supportedAlgorithms.define('AES-KW', 'exportKey', )

@@ -145,6 +145,8 @@ /**

let publicKey = spawnSync('openssl', ['rsa', '-pubout'], { input: privateKey }).stdout
keypair.privateKey = privateKey.toString('ascii')
keypair.publicKey = publicKey.toString('ascii')
try {
keypair.privateKey = privateKey.toString('ascii')
keypair.publicKey = publicKey.toString('ascii')
} catch (error){
throw new OperationError(error.message)
}
// - what is this bit option, where do we get the value from in this api?

@@ -151,0 +153,0 @@ //let key = new RSA({b:512})

@@ -24,3 +24,3 @@ /**

/**
* Test code
* Test code
*/

@@ -61,7 +61,7 @@ const good_iv = Buffer.from([ 220, 29, 37, 164, 41, 84, 153, 197, 157, 122, 156, 254, 196, 161, 114, 74 ])

before(() => {
aes = new AES_CBC({ name: "AES-CBC", length: 256 })
before(() => {
aes = new AES_CBC({ name: "AES-CBC", length: 256 })
key = aes.importKey(
"jwk",
{
"jwk",
{
kty: "oct",

@@ -72,12 +72,12 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

},
{
{
name: "AES-CBC",
},
true,
["encrypt", "decrypt"]
true,
["encrypt", "decrypt"]
)
data = new TextEncoder().encode('signed with Chrome Webcrypto')
signature = new Uint8Array([
76, 82, 211, 155, 13, 154, 24, 6, 156, 203, 50,
171, 210, 17, 88, 145, 32, 225, 125, 119, 179,
76, 82, 211, 155, 13, 154, 24, 6, 156, 203, 50,
171, 210, 17, 88, 145, 32, 225, 125, 119, 179,
197, 224, 210, 122, 43, 255, 159, 59, 195, 206, 210])

@@ -98,3 +98,3 @@ })

Buffer.from(aes.encrypt({name: "AES-CBC", iv: good_iv},key,data))
.should.eql(Buffer.from(signature.buffer))
.should.eql(Buffer.from(signature.buffer))
})

@@ -108,7 +108,7 @@ }) // encrypt

let aes, key, data, signature
before(() => {
aes = new AES_CBC({ name: "AES-CBC", length: 256 })
before(() => {
aes = new AES_CBC({ name: "AES-CBC", length: 256 })
key = aes.importKey(
"jwk",
{
"jwk",
{
kty: "oct",

@@ -119,12 +119,12 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

},
{
{
name: "AES-CBC",
},
true,
["encrypt", "decrypt"]
true,
["encrypt", "decrypt"]
)
data = new Uint8Array([
76, 82, 211, 155, 13, 154, 24, 6, 156,
203, 50, 171, 210, 17, 88, 145, 32, 225,
125, 119, 179, 197, 224, 210, 122, 43,
76, 82, 211, 155, 13, 154, 24, 6, 156,
203, 50, 171, 210, 17, 88, 145, 32, 225,
125, 119, 179, 197, 224, 210, 122, 43,
255, 159, 59, 195, 206, 210])

@@ -142,7 +142,7 @@ signature = new TextEncoder().encode('signed with Chrome Webcrypto')

aes.decrypt({name: "AES-CBC", iv: good_iv},key,data).should.be.instanceof(ArrayBuffer)
})
})
it('should return a valid encryption', () => {
Buffer.from(aes.decrypt({name: "AES-CBC", iv: good_iv},key,data))
.should.eql(Buffer.from(signature.buffer))
.should.eql(Buffer.from(signature.buffer))
})

@@ -156,3 +156,3 @@ }) // decrypt

let alg, aes, cryptoKey
before(() => {

@@ -163,7 +163,7 @@ alg = {

}
aes = new AES_CBC(alg)
aes = new AES_CBC(alg)
return Promise.resolve()
.then(() => cryptoKey = aes.generateKey(alg,true,["encrypt", "decrypt"]))
})
it('should throw with invalid usages', () => {

@@ -181,3 +181,3 @@ expect(() => {

it('should return CryptoKey', () => {
it('should return CryptoKey', () => {
cryptoKey.should.be.instanceof(CryptoKey)

@@ -232,3 +232,3 @@ })

})
describe('with "raw" format', () => {

@@ -245,3 +245,3 @@ let alg, aes, raw, cryptoKey

.then(() => cryptoKey = aes.importKey("raw",raw,{name:"AES-CBC"},true,["encrypt", "decrypt"]) )
})
})

@@ -280,3 +280,3 @@ it('should expect a suitable raw length', () => {

describe('with "jwk" format', () => {
describe('with "jwk" format', () => {
let alg, aes, key, cryptoKey

@@ -289,3 +289,3 @@ before(() => {

aes = new AES_CBC(alg)
key = {
key = {
kty: "oct",

@@ -308,3 +308,3 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "WRONG",

@@ -320,3 +320,3 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -331,3 +331,3 @@ alg: "A256CBC",

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -338,3 +338,3 @@ k: "c7WsUB6msAgIdDxTnT13Yw",

}, {name:"AES-CBC"} , false, ['encrypt','decrypt'])
}).to.throw('Algorithm "A128CBC" must be 128 bits in length')
}).to.throw('Algorithm "A128CBC" must be 128 bits in length')
})

@@ -344,3 +344,3 @@

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -351,3 +351,3 @@ k: "c7WsUB6msAgIdDxTnT13YwY7SQjYVmrq",

}, {name:"AES-CBC"} , false, ['encrypt','decrypt'])
}).to.throw('Algorithm "A192CBC" must be 192 bits in length')
}).to.throw('Algorithm "A192CBC" must be 192 bits in length')
})

@@ -357,3 +357,3 @@

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -364,3 +364,3 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

}, {name:"AES-CBC"} , false, ['encrypt','decrypt'])
}).to.throw('Algorithm "A256CBC" must be 256 bits in length')
}).to.throw('Algorithm "A256CBC" must be 256 bits in length')
})

@@ -370,3 +370,3 @@

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -377,3 +377,3 @@ k: "Y0zt37",

}, {name:"AES-CBC"} , false, ['encrypt','decrypt'])
}).to.throw('Algorithm and data length mismatch')
}).to.throw('Algorithm and data length mismatch')
})

@@ -383,3 +383,3 @@

expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -399,6 +399,6 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

})
it('should expect non extractable to not be extractable', () => {
expect(() => {
aes.importKey('jwk',{
aes.importKey('jwk',{
kty: "oct",

@@ -450,4 +450,4 @@ k: "Y0zt37HgOx-BY7SQjYVmrqhPkO44Ii2Jcb9yydUDPfE",

expect(() => {
aes.exportKey('raw',{})
}).to.throw('Missing key material')
aes.exportKey('raw',{})
}).to.throw('Missing key material')
})

@@ -457,3 +457,3 @@

expect(() => {
aes.exportKey('WRONG',{handle:"Something"})
aes.exportKey('WRONG',{handle:"Something"})
}).to.throw('WRONG is not a supported key format')

@@ -483,3 +483,3 @@ })

})//raw
describe('with "jwk" format', () => {

@@ -513,3 +513,3 @@ let alg, aes, key, jwk

kty: "oct",
k: "c7WsUB6msAgIdDxTnT13Yw",
k: "c7WsUB6msAgIdDxTnT13Yw",
alg: "A128CBC",

@@ -523,3 +523,3 @@ ext: true

kty: "oct",
k: "c7WsUB6msAgIdDxTnT13YwY7SQjYVmrq",
k: "c7WsUB6msAgIdDxTnT13YwY7SQjYVmrq",
alg: "A192CBC",

@@ -542,3 +542,1 @@ ext: true

})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc