小编gop*_*her的帖子

如何使用secp256r1类型的椭圆曲线密钥对在Android中加密和解密数据?

我需要使用 NIST P-256 椭圆曲线来加密和解密数据。现在我已经生成了密钥对,但是我如何使用它们来加密和解密呢?

官网只说了如何使用这个ec密钥对进行签名/验证,但是我想知道如何使用这个ec密钥对进行加密/解密。

网站:https : //developer.android.com/reference/android/security/keystore/KeyGenParameterSpec#example : -nist-p-256-ec-key-pair-for-signingverification-using-ecdsa

生成 NIST P-256 密钥对代码:

        val kpg: KeyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore")
        val parameterSpec =
            KeyGenParameterSpec.Builder("container", KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
                .setAlgorithmParameterSpec(ECGenParameterSpec("secp256r1"))
                .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384, KeyProperties.DIGEST_SHA512)
                .build()
        kpg.initialize(parameterSpec)
        val keyPair = kpg.generateKeyPair()

        val ecPublicKey = keyPair.public as ECPublicKey
        val ecPrivateKey = keyPair.private as ECPrivateKey
Run Code Online (Sandbox Code Playgroud)

encryption android elliptic-curve kotlin

8
推荐指数
2
解决办法
3025
查看次数

标签 统计

android ×1

elliptic-curve ×1

encryption ×1

kotlin ×1