小编Ore*_*rin的帖子

如何在 Dart 中使用 encrypt 实现 rsa 加密

我有一个用 Koltin 编写的包,我想用 Dart 重写它。我一直在尝试使用encryptpointycastle。但我遇到了问题

我将如何在 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)

encryption android dart kotlin flutter

0
推荐指数
1
解决办法
2983
查看次数

标签 统计

android ×1

dart ×1

encryption ×1

flutter ×1

kotlin ×1