Make sample use box

This commit is contained in:
Ugljesa Jovanovic 2021-02-22 22:56:28 +01:00
parent 0222b967bc
commit d4955dc7cd
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F

View File

@ -32,9 +32,11 @@ class MainActivity : AppCompatActivity() {
val senderKeypair = Box.keypair()
val recipientKeypair = Box.keypair()
val messageNonce = Random(0).nextUBytes(crypto_box_NONCEBYTES)
val encrypted = Box.easy(message, messageNonce, recipientKeypair.publicKey, senderKeypair.secretKey)
val decrypted = Box.openEasy(encrypted, messageNonce, senderKeypair.publicKey, recipientKeypair.secretKey)
val builder = StringBuilder()
val encrypted = Box.easy(message, messageNonce, recipientKeypair.publicKey, senderKeypair.secretKey)
builder.appendLine("Encrypted: ${encrypted.toHexString()}")
val decrypted = Box.openEasy(encrypted, messageNonce, senderKeypair.publicKey, recipientKeypair.secretKey)
builder.appendLine("Decrypted: ${decrypted.decodeFromUByteArray()}")
try {
val tampered = encrypted.copyOf()