INNER CODE UNIT · Kotlin

publicPrivateKeyEncryptionStep2

terl/lazysodium-java · sample-app/src/main/kotlin/Main.kt:147

    private fun publicPrivateKeyEncryptionStep2(aliceKp: KeyPair, bobKp: KeyPair) {
        val message = "Cryptography is the best"
        printStep(
            "2",
            "Encrypting a message with a public private keypair",
            "Alice wants to send the message '$message' to Bob."
        )

        // Make sure that we provide the secret key of Alice encrypting
        // the message using Bob's public key.
        val aliceToBobKp = KeyPair(bobKp.publicKey, aliceKp.secretKey)
        val nonce: ByteArray = lazySodium.nonce(Box.NONCEBYTES)
        val encrypted: String = lazySodium.cryptoBoxEasy(message, nonce, aliceToBobKp)
        log()
        logt("Alice uses her private key to encrypt the message with Bob's public key.")
        logt("Encryption result: $encrypted")
        log()
        publicPrivateKeyEncryptionStep3(encrypted, nonce, aliceKp, bobKp)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…