Skip to content

Commit

Permalink
Merge pull request #2 from Dead4W/async
Browse files Browse the repository at this point in the history
Best perfomance with WebCrypto
  • Loading branch information
Dead4W authored Jan 6, 2021
2 parents dec3e0e + eba2c6e commit 5d332fd
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 305 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ Requirements

- CryptoJS (https://cryptojs.gitbook.io/docs/)
- core.js
- cipher-core.js
- aes.js
- hmac.js
- sha256.js
- pad-nopadding.js
- enc-utf16.js
- enc-uint8array.js (Custom Uint8Array encoding)

Expand All @@ -39,25 +34,22 @@ const aes = AesCrypt();

let fileSecret = document.getElementById("fileSecret").files[0];

var password = "foopassword"
let password = "foopassword"

// encryption/decryption

// **IMPORTANT** Only for workers!
let progress_callback = (current) => {let percent = current * 100;};

// encrypt typed array (Uint8Array)
aes.encrypt(fileSecret, password, progress_callback).then((encrypted) => {
aes.encrypt(fileSecret, password).then((encrypted) => {
console.log(encrypted);
});

let fileEncrypted = document.getElementById("fileEncrypted").files[0];

// decrypt typed array (Uint8Array)
aes.decrypt(fileEncrypted, password, progress_callback).then((decrypted) => {
aes.decrypt(fileEncrypted, password).then((decrypted) => {

// transform Uint8Array to Latin1 string
let secret = aes.utils.bytes_to_latin1(decrypted);
let secret = aes.utils.bytes2str(decrypted);

console.log(secret);
});
Expand Down
5 changes: 0 additions & 5 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<head>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/cipher-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/aes.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/hmac.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/sha256.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/pad-nopadding.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/enc-utf16.min.js"></script>
<script src="libs/enc-uint8array.min.js"></script>
<script src="libs/aes_crypt.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion demo/libs/aes_crypt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions demo/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ let base_libs = "libs/";

self.importScripts(
base_cdn + "core.min.js",
base_cdn + "cipher-core.min.js",
base_cdn + "aes.min.js",
base_cdn + "hmac.min.js",
base_cdn + "sha256.min.js",
base_cdn + "pad-nopadding.min.js",
base_cdn + "enc-utf16.min.js",
base_libs + "enc-uint8array.min.js",
base_libs + "aes_crypt.min.js",
Expand Down
Loading

0 comments on commit 5d332fd

Please sign in to comment.