如何在Java

时间:2018-10-18 21:39:03

标签: java amazon-web-services security hsm

我有下一个代码 我加载密钥

public static RSAPublicKey getKey(String filename)
            throws Exception {

            byte[] keyBytes = Files.readAllBytes(Paths.get(filename));

            X509EncodedKeySpec spec =
              new X509EncodedKeySpec(keyBytes);
            KeyFactory kf = KeyFactory.getInstance("RSA");
            return (RSAPublicKey)kf.generatePublic(spec);
    }

我调用方法

RSAPublicKey pubKey = (RSAPublicKey) GeneraKeysRsa.getKey(file);

现在我尝试将RSAPublicKey转换为CaviumRSAPublicKey

CaviumRSAPublicKey key = (CaviumRSAPublicKey) pubKey;

但是我得到下一个:

ClassCastException: sun.security.rsa.RSAPublicKeyImpl cannot be cast to com.cavium.key.CaviumRSAPublicKey

有什么主意吗?

谢谢。

0 个答案:

没有答案