我有一个用 Koltin 编写的包,我想用 Dart 重写它。我一直在尝试使用encrypt和pointycastle。但我遇到了问题
我将如何在 Dart 中编写这个实现。
我开始尝试对公钥进行编码
var modulusBytes = base64.decode(publicKey!);
import android.util.Base64
import java.security.KeyFactory
import java.security.NoSuchAlgorithmException
import java.security.PublicKey
import java.security.spec.InvalidKeySpecException
import java.security.spec.X509EncodedKeySpec
import javax.crypto.Cipher
object Crypto {
private const val PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADfafwfegRHqfkBiKGn/rrgrgrgrrgg" +
"2wkeSokw2OJrCI+d6YGJPrHHx+nmb/Qn885/R01Gw6d7M824qofmCvkCAwEAAQ=="
private const val ALGORITHM = "RSA"
private const val CIPHER = "RSA/ECB/PKCS1Padding"
private fun encrypt(text: String, key: PublicKey): ByteArray? {
var cipherText: ByteArray? = null
try {
// get an RSA cipher object
val cipher = Cipher.getInstance(CIPHER)
//init …
Run Code Online (Sandbox Code Playgroud)