-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestCryptoBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.trustwallet.core.app.utils | ||
|
||
import com.trustwallet.core.app.utils.toHexBytes | ||
import com.trustwallet.core.app.utils.toHex | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import wallet.core.jni.* | ||
|
||
class TestCryptoBox { | ||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testEncryptDecryptEasy() { | ||
val mySecret = CryptoBoxSecretKey() | ||
val myPubkey = mySecret.publicKey | ||
|
||
val otherSecret = CryptoBoxSecretKey() | ||
val otherPubkey = otherSecret.publicKey | ||
|
||
val message = "Well done is better than well said. -Benjamin Franklin" | ||
val encrypted = CryptoBox.encryptEasy(mySecret, otherPubkey, message.toByteArray()) | ||
|
||
// Step 2. Make sure the Box can be decrypted by the other side. | ||
val decrypted = CryptoBox.decryptEasy(otherSecret, myPubkey, encrypted) | ||
assertEquals(decrypted.toString(Charsets.UTF_8), message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
import WalletCore | ||
import XCTest | ||
|
||
class CryptoBoxTests: XCTestCase { | ||
func testEncryptDecryptEasy() { | ||
let mySecret = CryptoBoxSecretKey() | ||
let myPubkey = mySecret.getPublicKey() | ||
|
||
let otherSecret = CryptoBoxSecretKey() | ||
let otherPubkey = otherSecret.getPublicKey() | ||
|
||
let message = "Well done is better than well said. -Benjamin Franklin" | ||
let encrypted = CryptoBox.encryptEasy(mySecret: mySecret, otherPubkey: otherPubkey, message: Data(message.utf8)) | ||
|
||
// Step 2. Make sure the Box can be decrypted by the other side. | ||
let decrypted = CryptoBox.decryptEasy(mySecret: otherSecret, otherPubkey: myPubkey, encrypted: encrypted)! | ||
let decryptedStr = String(bytes: decrypted, encoding: .utf8) | ||
XCTAssertEqual(decryptedStr, message) | ||
} | ||
} |