From 39ed6ad7e3b7e942f2ad36982c307fd215049d01 Mon Sep 17 00:00:00 2001 From: tursom Date: Mon, 2 Mar 2020 02:18:17 +0800 Subject: [PATCH] update RSA, add public RSA object --- src/main/kotlin/cn/tursom/core/encrypt/RSA.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/cn/tursom/core/encrypt/RSA.kt b/src/main/kotlin/cn/tursom/core/encrypt/RSA.kt index 8205fa5..bb44d57 100644 --- a/src/main/kotlin/cn/tursom/core/encrypt/RSA.kt +++ b/src/main/kotlin/cn/tursom/core/encrypt/RSA.kt @@ -19,6 +19,14 @@ class RSA(val publicKey: RSAPublicKey, val privateKey: RSAPrivateKey? = null) : val decryptMaxLen = keySize / 8 val encryptMaxLen = decryptMaxLen - 11 + val public by lazy { + if (privateKey == null) { + this + } else { + RSA(publicKey) + } + } + private val encryptCipher = Cipher.getInstance("RSA")!! private val decryptCipher = Cipher.getInstance("RSA")!!