相关疑难解决方法(0)

将密钥转换为字节,如何将其转换回秘密密钥?

我使用以下代码将密钥转换为字节

SecretKey key = KeyGenerator.getInstance("DES").generateKey();
byte[] bkey=key.getEncoded();
Run Code Online (Sandbox Code Playgroud)

现在如何从中获取密钥bkey?我试过了:

SecretKeySpec secretkey = new SecretKeySpec(bkey,"DES");   
SecretKeyFactory sfkey = SecretKeyFactory.getInstance("DES");
SecretKey skey = sfkey.generateSecret(secretkey);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Error during Exception java.security.spec.InvalidKeySpecException: Inappropriate key specification
Run Code Online (Sandbox Code Playgroud)

java security byte des

17
推荐指数
1
解决办法
4万
查看次数

sun.security.rsa.RSAPublicKeyImpl的开源替换

由于使用RSAPublicKeyImpl,我收到一些警告:

警告:RSAPublicKeyImpl是内部专有API,可能会在以后的发行版中删除。import sun.security.rsa.RSAPublicKeyImpl;

我试图找到替代产品,但是没有运气。此类的开源替代品是什么?

java encoding cryptography rsa public-key

2
推荐指数
1
解决办法
1696
查看次数

Java:只拥有PrivateKey来恢复公钥?可能?

来源: 如何从byte []数组中恢复RSA公钥?

这是我的KeyPair生成方法:

    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC");
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        ECGenParameterSpec ecSpec = new ECGenParameterSpec("prime192v1");
        // Initialize the key generator and generate a KeyPair
        keyGen.initialize(ecSpec, random); // 256 bytes provides an
                                            // acceptable security level
        KeyPair keyPair = keyGen.generateKeyPair();
        // Set the public and private keys from the keyPair
        privateKey = keyPair.getPrivate();
        publicKey = keyPair.getPublic();


        System.out.println("Private and public keys:");
        System.out.println("PRIVATE: " + StringUtil.getStringFromKey(this.privateKey));
        System.out.println("PUBLIC: " + StringUtil.getStringFromKey(this.publicKey));

    } catch (Exception e) {
        throw new RuntimeException(e); …
Run Code Online (Sandbox Code Playgroud)

java recover private-key generate

-1
推荐指数
1
解决办法
288
查看次数