A simple crypto library, based on Rust and WebAssembly.
Vite example:
use your favorite package manager.
pnpm install rs-crypto
In your project's vite.config.ts
or vite.config.js
:
{
...
optimizeDeps: {
exclude: ['rs-crypto'],
},
...
}
In your project's entry, default main.ts
or main.js
:
...
import init from 'rs-crypto';
await init();
...
- Import
RSAEncrypt
orRSADecrypt
Class - Instantiate
RSAEncrypt
orRSADecrypt
- 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)
- Import
SHA2
Method - Call Method.
import { SHA2 } from 'rs-crypto'
const digest = SHA2.sha256(need_to_digest)
- 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
- ……
- RSA
- Improve docs & human readability
- Console print error
- RSA
- ……
- Optimize Performance
- Optimize compile args
- ……
- Author: yangxu52 A Junior Rust developer
Invite you to collaborate with me to maintain the repository together
MIT License