简体   繁体   English

是否可以将自己的密钥放入AndroidKeyStore?

[英]Is possible to put own key to AndroidKeyStore?

I am thinking about this question: 我在考虑这个问题:

Is possible to put my own key to AndroidKeyStore and using it for other operations (signing some text/docs)? 是否可以将自己的密钥AndroidKeyStore并将其用于其他操作(签署一些文本/文档)?

I have generated a PostQuantum keys (priv/pub) for signing algorithm SPHINCS , that includes BouncyCastle library. 我已经为签名算法SPHINCS生成了一个PostQuantum密钥( PostQuantum /发布),其中包括BouncyCastle库。

Is there some ways, how to initialize my plan? 有什么方法,如何初始化我的计划?

Thank you for your hints :) 谢谢您的提示:)

There is an example code, how I am generating a priv/pub keys by BouncyCastle SPHINCS : 有一个示例代码,我如何通过BouncyCastle SPHINCS生成priv / pub密钥:

SPHINCS256KeyPairGenerator generator = new SPHINCS256KeyPairGenerator();
generator.init(new SPHINCS256KeyGenerationParameters(new RiggedRandom(), new SHA3Digest(256)));
AsymmetricCipherKeyPair kp = generator.generateKeyPair();

SPHINCSPrivateKeyParameters priv = (SPHINCSPrivateKeyParameters)kp.getPrivate();
SPHINCSPublicKeyParameters pub = (SPHINCSPublicKeyParameters)kp.getPublic();

Try something like this(Sample for Andorid M(6.0)+ ) 尝试这样的事情(Andorid M(6.0)+的示例)

    @TargetApi(Build.VERSION_CODES.M)
        private void initGeneratorWithKeyGenParameterSpec() {
            try {
                KeyPairGenerator generator = KeyPairGenerator.getInstance("ALGORITHM", "AndroidKeyStore");
                String alias = "myAlias";
                Calendar startDate = Calendar.getInstance();
                Calendar endDate = Calendar.getInstance();
                endDate.add(Calendar.YEAR, 20);
                KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(
                        alias, KeyProperties.PURPOSE_ENCRYPT|KeyProperties.PURPOSE_DECRYPT)
                        .setCertificateSubject(new X500Principal("CN=" + alias))
                        .setCertificateSerialNumber(BigInteger.valueOf(1337))
                        .setCertificateNotBefore(startDate.getTime())
                        .setCertificateNotAfter(endDate.getTime())
                        .setBlockModes(KeyProperties.BLOCK_MODE_ECB)
                        .setDigests(KeyProperties.DIGEST_SHA256)
                        .setKeySize(2048)
                        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1);
                generator.initialize(builder.build());
                generator.generateKeyPair();
            } catch (Exception e) {
                mLogger.logException(Logger.Level.ERROR, Logger.Category.ENCRYPTION, "KeyStoreWrapper", "initGeneratorWithKeyGenParameterSpec()", e);
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以生成64字节(256位)密钥并使用AndroidKeyStore存储/检索它? - Is it possible to generate a 64-byte (256-bit) key and store/retrieve it with AndroidKeyStore? AndroidKeyStore 密钥生成期间的 IllegalArgumentException(无法解析的日期) - IllegalArgumentException (Unparseable date) during AndroidKeyStore key generation 是否有可能将我自己的课程纳入第三方套餐? - Is it possible to put my own class into a 3rd party package? AndroidKeyStore无法生成证书 - AndroidKeyStore cannot generate certificate 无法将 AndroidKeyStore 序列化为 OutputStream - Can not serialize AndroidKeyStore to OutputStream 自己的MultiMap实现,放置问题 - own MultiMap implementation, problems with put 是否可以从 LinkedHashMap 中提取键集,对其应用排序算法并将其放回映射中? - Is it possible to extract the key set from a LinkedHashMap, apply a sorting algorithm on it and put it back into the map? 为什么 AndroidKeyStore 将 PrivateKeyEntry 转换为 TrustedCertifiateEntry? - Why is AndroidKeyStore transforming PrivateKeyEntry into a TrustedCertifiateEntry? AndroidKeystore 是特定于应用程序还是特定于设备? - Is the AndroidKeystore app specific or device specific? 是否可以将FormLayout放入GridLayout? - Is it possible to put FormLayout into GridLayout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM