rs-crypto
v0.0.1-beta.3
Published
A simple crypto library, based on Rust and WebAssembly.
Downloads
8
Maintainers
Readme
RS-Crypto
A simple crypto library, based on Rust and WebAssembly.
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
- 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)
4.2 Not require a key: Example SHA2
digest
- Import
SHA2
Method - Call Method.
import { SHA2 } from 'rs-crypto'
const digest = SHA2.sha256(need_to_digest)
Roadmap
- Add more
- [ ] RSA
- [x] PKCS#8 PEM Import
- [x] PKCS1v1.5 Encrypt/Decrypt
- [x] PKCS1v2(OAEP) Encrypt/Decrypt (padding digest
sha256
) - [ ] PKCS1v1.5 Sign/Verify
- [ ] PSS Sign/Verify
- [ ] AES
- [x] SHA2
- [x] sha224
- [x] sha256
- [x] sha384
- [x] sha512
- [ ] HMAC
- [ ] ……
- [ ] RSA
- Improve docs & human readability
- [x] Console print error
- [x] RSA
- [ ] ……
- Optimize Performance
- [x] Optimize compile args
- [ ] ……
Contributors
- Author: yangxu52 A Junior Rust developer
Invite you to collaborate with me to maintain the repository together
Star History
License
MIT License