Skip to content

Commit 98f6630

Browse files
Merge pull request #115 from klever-io/feat/add-encrypt-gcm-interface-for-wasm
export encrypt (default gcm) to wasm
2 parents 6c3a8b4 + 5f8367a commit 98f6630

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/kos-web/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ pub fn decrypt(data: &[u8], password: &str) -> Result<Vec<u8>, Error> {
3737
cipher::decrypt(data, password).map_err(|e| Error::Cipher(format!("{}", e)))
3838
}
3939

40+
/// Encrypt for GCM the given data with the given password.
41+
/// Data will have the algorithm tag prepended to it (1 byte).
42+
#[wasm_bindgen(js_name = "encrypt")]
43+
pub fn encrypt(data: &[u8], password: &str) -> Result<Vec<u8>, Error> {
44+
cipher::encrypt(cipher::CipherAlgo::GMC, data, password)
45+
.map_err(|e| Error::Cipher(format!("{}", e)))
46+
}
47+
4048
/// Create pem file from tag and data
4149
#[wasm_bindgen(js_name = "toPem")]
4250
pub fn to_pem(tag: String, data: &[u8]) -> Result<String, Error> {

0 commit comments

Comments
 (0)