From 48dfbc2b95db797b611235702f65ff1912625b7f Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Mon, 14 Nov 2022 20:26:42 +0700 Subject: [PATCH] Fixing the format --- .vscode/settings.json | 18 ++-- README.md | 187 ++++++++++++++++++++++-------------------- deno.json | 5 ++ src/hmac/mod.ts | 8 +- src/rsa/eme_oaep.ts | 10 +-- src/rsa/import_key.ts | 1 - src/rsa/primitives.ts | 2 +- 7 files changed, 120 insertions(+), 111 deletions(-) create mode 100644 deno.json diff --git a/.vscode/settings.json b/.vscode/settings.json index dda860a..2d223bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,9 @@ -{ - "editor.tabSize": 2, - "deno.enable": true, - "files.eol": "\n", - "editor.formatOnSave": true, - "[typescript]": { - "editor.defaultFormatter": "denoland.vscode-deno" - } -} +{ + "editor.tabSize": 2, + "deno.enable": true, + "files.eol": "\n", + "editor.formatOnSave": true, + "[typescript]": { + "editor.defaultFormatter": "denoland.vscode-deno" + } +} diff --git a/README.md b/README.md index be05dd8..6e709b9 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,96 @@ -# God Crypto - -> **NO LONGER MAINTAIN** -> I have been very busy lately and can no longer maintain this project and since there is roadmap for Deno for standard crypto library: https://github.com/denoland/deno/issues/11690. I feel there is no longer need for this library. - - - -![test](https://github.com/invisal/god-crypto/workflows/test//badge.svg) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=invisal_god_crypto&metric=alert_status)](https://sonarcloud.io/dashboard?id=invisal_god_crypto) - -A pure Javascript/Typescript cryptography implementation for Deno. We will try to use WebCrypto if available, then fallback pure Javascript implementation. - -## References - -### Supported Algorithms - -- [**AES (Advanced Encryption Standard)**](https://github.com/invisal/god_crypto/wiki/AES) - - - Supports Block Ciper Mode: CBC, CFB, and ECB - -- [**RSA (Rivest–Shamir–Adleman)**](https://github.com/invisal/god_crypto/wiki/RSA) - - - Supports RSA-PKCS1 v1.5 and RSA-OAEP padding - - Supports RSASSA-PSS signature - - Supports RSASSA-PKCS1-v1_5 signature - -- [**HMAC**](https://github.com/invisal/god_crypto/wiki/HMAC) - -### Applications - -- [**HOTP (HMAC-based One-time Password)**](https://github.com/invisal/god_crypto/wiki/HOTP) -- [**TOTP ( - Time-based One-time Password)**](https://github.com/invisal/god_crypto/wiki/TOTP) - -### Ultities - -Some useful ultities that you can use - -- [encode](https://github.com/invisal/god_crypto/wiki/encode) -- [BER Writer](https://github.com/invisal/god_crypto/wiki/BER) - -Click here for complete document: [Complete Documents](https://github.com/invisal/god_crypto/wiki) - -## Modules - -You can choose to include the whole `god_crypto` implementation or just include module that you need. - -``` -// Load everything -import { AES, RSA, TOTP, hmac, encode } from "https://deno.land/x/god_crypto/mod.ts"; - -// Load what you need -import { AES } from "https://deno.land/x/god_crypto/aes.ts"; -import { RSA } from "https://deno.land/x/god_crypto/rsa.ts"; -import { TOTP } from "https://deno.land/x/god_crypto/otp.ts"; -import { hmac } from "https://deno.land/x/god_crypto/hmac.ts"; -``` - ---- - -## Examples - -```typescript -import { AES } from "https://deno.land/x/god_crypto/aes.ts"; - -const aes = new AES("Hello World AES!", { - mode: "cbc", - iv: "random 16byte iv", -}); -const cipher = await aes.encrypt("This is AES-128-CBC. It works."); -console.log(cipher.hex()); -// 41393374609eaee39fbe57c96b43a9da0d547c290501be50f983ecaac6c5fd1c - -const plain = await aes.decrypt(cipher); -console.log(plain.toString()); -// This is AES-128-CBC. It works. -``` - -```typescript -import { RSA } from "https://deno.land/x/god_crypto/rsa.ts"; - -// Parsing public/private key -const publicKey = RSA.parseKey(Deno.readTextFileSync("./public.pem")); -const privateKey = RSA.parseKey(Deno.readTextFileSync("./private.pem")); - -const cipher = await new RSA(publicKey).encrypt("Hello World"); -console.log(ciper.base64()); - -const plain = await new RSA(privateKey).decrypt(cipher); -console.log(plain.toString()); -``` +# God Crypto + +> **NO LONGER MAINTAIN** I have been very busy lately and can no longer maintain +> this project and since there is roadmap for Deno for standard crypto library: +> https://github.com/denoland/deno/issues/11690. I feel there is no longer need +> for this library. + + + +![test](https://github.com/invisal/god-crypto/workflows/test//badge.svg) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=invisal_god_crypto&metric=alert_status)](https://sonarcloud.io/dashboard?id=invisal_god_crypto) + +A pure Javascript/Typescript cryptography implementation for Deno. We will try +to use WebCrypto if available, then fallback pure Javascript implementation. + +## References + +### Supported Algorithms + +- [**AES (Advanced Encryption Standard)**](https://github.com/invisal/god_crypto/wiki/AES) + + - Supports Block Ciper Mode: CBC, CFB, and ECB + +- [**RSA (Rivest–Shamir–Adleman)**](https://github.com/invisal/god_crypto/wiki/RSA) + + - Supports RSA-PKCS1 v1.5 and RSA-OAEP padding + - Supports RSASSA-PSS signature + - Supports RSASSA-PKCS1-v1_5 signature + +- [**HMAC**](https://github.com/invisal/god_crypto/wiki/HMAC) + +### Applications + +- [**HOTP (HMAC-based One-time Password)**](https://github.com/invisal/god_crypto/wiki/HOTP) +- [**TOTP ( + Time-based One-time Password)**](https://github.com/invisal/god_crypto/wiki/TOTP) + +### Ultities + +Some useful ultities that you can use + +- [encode](https://github.com/invisal/god_crypto/wiki/encode) +- [BER Writer](https://github.com/invisal/god_crypto/wiki/BER) + +Click here for complete document: +[Complete Documents](https://github.com/invisal/god_crypto/wiki) + +## Modules + +You can choose to include the whole `god_crypto` implementation or just include +module that you need. + +``` +// Load everything +import { AES, RSA, TOTP, hmac, encode } from "https://deno.land/x/god_crypto/mod.ts"; + +// Load what you need +import { AES } from "https://deno.land/x/god_crypto/aes.ts"; +import { RSA } from "https://deno.land/x/god_crypto/rsa.ts"; +import { TOTP } from "https://deno.land/x/god_crypto/otp.ts"; +import { hmac } from "https://deno.land/x/god_crypto/hmac.ts"; +``` + +--- + +## Examples + +```typescript +import { AES } from "https://deno.land/x/god_crypto/aes.ts"; + +const aes = new AES("Hello World AES!", { + mode: "cbc", + iv: "random 16byte iv", +}); +const cipher = await aes.encrypt("This is AES-128-CBC. It works."); +console.log(cipher.hex()); +// 41393374609eaee39fbe57c96b43a9da0d547c290501be50f983ecaac6c5fd1c + +const plain = await aes.decrypt(cipher); +console.log(plain.toString()); +// This is AES-128-CBC. It works. +``` + +```typescript +import { RSA } from "https://deno.land/x/god_crypto/rsa.ts"; + +// Parsing public/private key +const publicKey = RSA.parseKey(Deno.readTextFileSync("./public.pem")); +const privateKey = RSA.parseKey(Deno.readTextFileSync("./private.pem")); + +const cipher = await new RSA(publicKey).encrypt("Hello World"); +console.log(ciper.base64()); + +const plain = await new RSA(privateKey).decrypt(cipher); +console.log(plain.toString()); +``` diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..1dc6e14 --- /dev/null +++ b/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "test": "deno test --allow-read --allow-write" + } +} diff --git a/src/hmac/mod.ts b/src/hmac/mod.ts index a769c55..10641cf 100644 --- a/src/hmac/mod.ts +++ b/src/hmac/mod.ts @@ -4,10 +4,10 @@ import { digest } from "../hash.ts"; /** * https://tools.ietf.org/html/rfc4868 - * - * @param algorithm - * @param key - * @param data + * + * @param algorithm + * @param key + * @param data */ export function hmac( algorithm: "sha1" | "sha256", diff --git a/src/rsa/eme_oaep.ts b/src/rsa/eme_oaep.ts index 00d1585..2c22fdd 100644 --- a/src/rsa/eme_oaep.ts +++ b/src/rsa/eme_oaep.ts @@ -5,11 +5,11 @@ import { RSAHashAlgorithm } from "./common.ts"; /** * https://tools.ietf.org/html/rfc3447#page-10 - * - * @param label - * @param m - * @param k - * @param algorithm + * + * @param label + * @param m + * @param k + * @param algorithm */ export function eme_oaep_encode( label: Uint8Array, diff --git a/src/rsa/import_key.ts b/src/rsa/import_key.ts index 377f8ee..e5c5c65 100644 --- a/src/rsa/import_key.ts +++ b/src/rsa/import_key.ts @@ -51,7 +51,6 @@ function rsa_import_jwk(key: JSONWebKey): RSAKeyParams { } /** - * * https://tools.ietf.org/html/rfc5280#section-4.1 * * @param key diff --git a/src/rsa/primitives.ts b/src/rsa/primitives.ts index 53fca0f..eb64f42 100644 --- a/src/rsa/primitives.ts +++ b/src/rsa/primitives.ts @@ -26,7 +26,7 @@ export function os2ip(m: Uint8Array): bigint { /** * MGF1 is a Mask Generation Function based on a hash function. * https://tools.ietf.org/html/rfc3447#appendix-B.2.1 - * + * * @param seed seed from which mask is generated, an octet string * @param length intended length in octets of the mask * @param hash Hash function