forked from tracker1/cryptico-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.html
119 lines (86 loc) · 3.82 KB
/
test.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script
language="JavaScript"
type="text/javascript"
src="../dist/cryptico.iife.js"
></script>
<script>
const api = cryptico.cryptico
function print(string) {
document.write(string + '\n\n')
}
print('<h1>Unsigned:</h1>')
let PassPhrase = 'The Moon is a Harsh Mistress.'
let Bits = 512
print("Matt's passphrase: " + PassPhrase)
print('Bit length: ' + Bits)
const MattsRSAkey = api.generateRSAKey(PassPhrase, Bits)
const MattsPublicKeyString = api.publicKeyString(MattsRSAkey)
print("Matt's public key string:")
print(MattsPublicKeyString)
let PlainText =
'Matt, I need you to encrypt UTF-8 strings which may include 中文字符.'
print("Sam's message: " + PlainText)
let EncryptionResult = api.encrypt(PlainText, MattsPublicKeyString)
print('The encrypted message:')
print(EncryptionResult.cipher)
let DecryptionResult = api.decrypt(
EncryptionResult.cipher,
MattsRSAkey,
)
print('The decrypted message:')
print(DecryptionResult.plaintext)
print('DecryptionResult.signature: ' + DecryptionResult.signature)
print('<h1>Signed, good signature:</h1>')
PassPhrase = "There Ain't No Such Thing As A Free Lunch."
Bits = 512
const SamsRSAkey = api.generateRSAKey(PassPhrase, Bits)
EncryptionResult = api.encrypt(
PlainText,
MattsPublicKeyString,
SamsRSAkey,
)
print(
"Sam's public key ID: " +
api.publicKeyID(api.publicKeyString(SamsRSAkey)),
)
print('The encrypted message:')
print(EncryptionResult.cipher)
DecryptionResult = api.decrypt(EncryptionResult.cipher, MattsRSAkey)
print('The decrypted message:')
print(DecryptionResult.plaintext)
print('DecryptionResult.signature: ' + DecryptionResult.signature)
print('The signature public key string:')
print(DecryptionResult.publicKeyString)
print('The signature public key ID:')
print(api.publicKeyID(DecryptionResult.publicKeyString))
print('<h1>Signed, forged signature:</h1>')
const ForgersPassPhrase = 'There Is Such Thing As A Free Lunch.'
const ForgersRSAkey = api.generateRSAKey(ForgersPassPhrase, Bits)
print(
"Forger's public key ID: " +
api.publicKeyID(api.publicKeyString(ForgersRSAkey)),
)
// const ForgedEncryptionResult = api.encrypt(
// PlainText,
// MattsPublicKeyString,
// ForgersRSAkey,
// )
EncryptionResult.cipher =
'KX2HnktN2B/PeYLlaQRLYDzIE8AV4lF03jK9CQ6bHrcs9IADIgAvJmaE0kGaxLXznULzsBI+d47d/5d7udUpDQ==?4/HL1YamY11E6vr6MkR+AtGKmO+Gjq7XBZuCRf8MpeFI1HcI/wNYNs+NCWRH2/yBDZ8Hp0jROtfIhQ8sQHPDLWmCHG+YgbFQsjzVEAqeDdfJyvv7DA61peJGa4/q58DLraHYo8QveiV6sXVtUq91jrxabgZ/N6Wr60/qj5pNWwS/q9Bv+wwnwTlQWikVNy3fxmoutH71OLbGJl7kZ/sDA3NScbuH8/TGmEtj906qXWmDdLUjN60GS7fFPsgX1p6Tff9DNrhqpzQXg90X3UgZet+BK/61IG0vadTHRx9I045CaqZkuzdNIQvdtdeoSUnWutME9CkPg1E5krv8F0Rb/qTQupn2a/PNaHRHh66brbOAzUf4ebx+69WX7PxYI7H3Rxibf75fQoqbv4rGHYTa4kF3LbrXNMcjouTNoyLg3xtt6psaPj5sY+ze1O/iwZXR9kVRiEAQyCP9UnNFTGRobg=='
print('The encrypted message:')
print(EncryptionResult.cipher)
DecryptionResult = api.decrypt(EncryptionResult.cipher, MattsRSAkey)
print('The decrypted message:')
print(DecryptionResult.plaintext)
print('DecryptionResult.signature: ' + DecryptionResult.signature)
print('The signature public key string:')
print(DecryptionResult.publicKeyString)
print('The signature public key ID:')
print(api.publicKeyID(DecryptionResult.publicKeyString))
</script>
</head>
<body style="font-family: monospace; white-space: pre"></body>
</html>