Skip to content

A simple crypto tools, based on Rust and WebAssembly.

License

Notifications You must be signed in to change notification settings

yangxu52/rs-crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RS-Crypto

A simple crypto library, based on Rust and WebAssembly.

MIT LICENSE  GitHub Stars  GitHub Forks

Usage

Vite example:

1. Install RS-Crypto

use your favorite package manager.

pnpm install rs-crypto

2. Add Optimize Exclude

In your project's vite.config.ts or vite.config.js:

{
    ...
    optimizeDeps: {
        exclude: ['rs-crypto'],
    },
    ...
}

3. Initialize WebAssembly Module

In your project's entry, default main.ts or main.js:

...
import init from 'rs-crypto';
await init();
...

4. Use Crypto Functions

4.1 Require a key: Example RSA encrypt/decrypt

  1. Import RSAEncrypt or RSADecrypt Class
  2. Instantiate RSAEncrypt or RSADecrypt
  3. Using instances to call methods
import { RSAEncrypt, RSADecrypt } from 'rs-crypto'

// encrypt
const rsaEnc = new RSAEncrypt(public_key) // PKCS#8 Text
const cipherText1 = rsaEnc.encrypt('hello world')
const cipherText2 = rsaEnc.encrypt('hello rust')

// decrypt
const rsaDec = new RSADecrypt(private_key) // PKCS#8 Text
const plainText1 = rsaDec.decrypt(cipherText1)
const plainText2 = rsaDec.decrypt(cipherText2)

4.2 Not require a key: Example SHA2 digest

  1. Import SHA2 Method
  2. Call Method.
import { SHA2 } from 'rs-crypto'
const digest = SHA2.sha256(need_to_digest)

Roadmap

  • Add more
    • RSA
      • PKCS#8 PEM Import
      • PKCS1v1.5 Encrypt/Decrypt
      • PKCS1v2(OAEP) Encrypt/Decrypt (padding digest sha256)
      • PKCS1v1.5 Sign/Verify
      • PSS Sign/Verify
    • AES
    • SHA2
      • sha224
      • sha256
      • sha384
      • sha512
    • HMAC
    • ……
  • Improve docs & human readability
    • Console print error
    • RSA
    • ……
  • Optimize Performance
    • Optimize compile args
    • ……

Contributors

  • Author: yangxu52 A Junior Rust developer

Invite you to collaborate with me to maintain the repository together

Star History

Star History

License

MIT License

About

A simple crypto tools, based on Rust and WebAssembly.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages