Giter Site home page Giter Site logo

simple-webcrypto's Introduction

simple-webcrypto

AES, RSA encryption/decryption and SHA, MD5 hashing using Web Crypto API in Node.js Node.js의 Web Crypto API를 이용해 AES, RSA 암·복호화, SHA, MD5 암호화를 지원

Installation

npm i simple-webcrypto

or

yarn add simple-webcrypto

or

pnpm add simple-webcrypto

Usage

import {
  aesEncrypt,
  aesDecrypt,
  generateRSAKeyPair,
  rsaEncrypt,
  rsaDecrypt,
  sha256,
  md5,
} from "crypto-utils";

// Example AES usage
(async () => {
  // AES key should be 128, 192, or 256 bits (16, 24, or 32 bytes)
  const key = crypto.getRandomValues(new Uint8Array(16));
  const message = "Hello, World!";

  const { iv, encrypted } = await aesEncrypt(message, key);
  const decryptedText = await aesDecrypt(encrypted, key, iv);

  console.log("Decrypted Text:", decryptedText);
})();

// Example RSA usage
(async () => {
  const { publicKey, privateKey } = await generateRSAKeyPair();

  const message = "Hello, World!";
  const publicKeyBuffer = new Uint8Array(
    await crypto.subtle.exportKey("spki", publicKey)
  );
  const privateKeyBuffer = new Uint8Array(
    await crypto.subtle.exportKey("pkcs8", privateKey)
  );

  const encrypted = await rsaEncrypt(message, publicKeyBuffer);
  const decryptedText = await rsaDecrypt(encrypted, privateKeyBuffer);

  console.log("Decrypted Text:", decryptedText);
})();

// Example SHA and MD5 usage
(async () => {
  const message = "Hello, World!";

  const sha256Hash = await sha256(message);
  console.log("SHA-256 Hash:", Buffer.from(sha256Hash).toString("hex"));

  const md5Hash = md5(message);
  console.log("MD5 Hash:", md5Hash);
})();

License

Open source licensed as MIT.

simple-webcrypto's People

Contributors

chj93 avatar

Watchers

 avatar

simple-webcrypto's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.