-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcryptotest.html
More file actions
36 lines (29 loc) · 887 Bytes
/
cryptotest.html
File metadata and controls
36 lines (29 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<html>
<head></head>
<body>
<script src="https://raw.githubusercontent.com/tonyg/js-nacl/master/lib/nacl_factory.js"></script>
<script>
var nacl = nacl_factory.instantiate();
function create_keys(password){
password = nacl.crypto_hash_string(password).subarray(0, 32);
return skp = nacl.crypto_sign_keypair_from_seed(password)
}
function encrypt_with_secret_key(msg,secret_key){
m = nacl.encode_utf8(msg);
return nacl.crypto_sign(m, secret_key);
}
function decrypt_with_public_key(crypt_msg,public_key){
m1 = nacl.crypto_sign_open(crypt_msg,public_key);
return nacl.decode_utf8(m1);
}
keys=create_keys("password")
public_key=keys.signPk
secret_key=keys.signSk
message="this is my message to the world"
crypt_msg=encrypt_with_secret_key(message,secret_key)
console.log(crypt_msg)
msg=decrypt_with_public_key(crypt_msg,public_key)
console.log(msg)
</script>
</body>
</html>