1
0
mirror of https://github.com/Luzifer/wasm-openssl.git synced 2024-09-18 23:42:57 +00:00

Update example / demo for new API

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-06-13 16:23:29 +02:00
parent 6765123358
commit 5ea2270568
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E

View File

@ -63,17 +63,7 @@
<script src="https://cdn.jsdelivr.net/combine/npm/vue@2.6.10,npm/bootstrap-vue@2.0.0-rc.28/dist/bootstrap-vue.min.js"></script> <script src="https://cdn.jsdelivr.net/combine/npm/vue@2.6.10,npm/bootstrap-vue@2.0.0-rc.28/dist/bootstrap-vue.min.js"></script>
<script src="wasm_exec.js"></script> <script src="wasm_exec.js"></script>
<script> <script>
function decryptResponse(plaintext, error) { // Define callback to be executed when openssl.wasm was initialized
console.log(["decryptResponse", plaintext, error])
}
function encryptResponse(ciphertext, error) {
console.log(["encryptResponse", ciphertext, error])
if (error === null) {
opensslDecrypt(ciphertext, "password", decryptResponse)
}
}
function opensslLoaded() { function opensslLoaded() {
app.$data.loaded = true app.$data.loaded = true
} }
@ -91,24 +81,26 @@
methods: { methods: {
decrypt() { decrypt() {
opensslDecrypt(this.ciphertext, this.passphrase, (plaintext, err) => { OpenSSL.decrypt(this.ciphertext, this.passphrase, (plaintext, err) => {
if (err) { if (err) {
this.error = err this.error = err
return return
} }
this.plaintext = plaintext this.plaintext = plaintext
this.error = ''
}) })
}, },
encrypt() { encrypt() {
opensslEncrypt(this.plaintext, this.passphrase, (ciphertext, err) => { OpenSSL.encrypt(this.plaintext, this.passphrase, (ciphertext, err) => {
if (err) { if (err) {
this.error = err this.error = err
return return
} }
this.ciphertext = ciphertext this.ciphertext = ciphertext
this.error = ''
}) })
}, },