【问题标题】:Java: Luna HSM Verify Sign using Public KeyJava:Luna HSM 使用公钥验证签名
【发布时间】:2015-03-08 10:54:57
【问题描述】:

使用 Java API,我正在尝试访问存储在 Luna HSM 中的公钥。即使我能够打印相应的公钥标签名称,但是当我尝试获取公钥时,我无法获得对该公钥的引用。这是代码sn-p:

        KeyStore ks = KeyStore.getInstance("Luna");
        ks.load(null, null); 
        lunaProvider = ks.getProvider();

        publicKey = (PublicKey) ks.getKey(alipayImpl.getHsmKeyStorePublicEntryName(), null);

        // ****************************************************************************
        // ** If the private keystore is not found, return original barcode string.  **
        // ****************************************************************************
        if (publicKey == null) {
            throw new Exception("Unable to acquire the Public Key " + alipayImpl.getHsmKeyStorePublicEntryName() + ", Hash will not be verified.");
        }
        // ***********************************************************
        // ** Create a Signature Object and sign the encrypted text **
        // ***********************************************************
        Signature signatureObject = Signature.getInstance(alipayImpl.getAlipaySignAlgorithm(), lunaProvider);

        signatureObject.initVerify(publicKey);
        signatureObject.update(signedMessage
                .getBytes(AlipayConstants.INPUT_CHARSET_VALUE));
        isValidSign = signatureObject.verify(Base64.decode(hash));

我正在正确登录 HSM。在访问私钥时,我没有任何问题。 Luna HSM 是否有任何限制,只能通过证书访问公钥?

提前致谢。

【问题讨论】:

    标签: public-key-encryption hsm


    【解决方案1】:

    正确答案是>

    LunaKey lk= LunaKey.LocateKeyByAlias("publicKeyName");

    但建议在查询 HSM 之前使密钥持久化。

    【讨论】:

      【解决方案2】:

      你有没有尝试过这样的事情:

      final KeyStore keyStore = KeyStore.getInstance("Luna");
      keyStore.load(null, null);
      
      final Certificate certificate = keyStore.getCertificate(alias);
      if (certificate == null) {
         throw new IllegalArgumentException(String.format("Certificate '%s' does not exists", alias));
      }
      
      final PublicKey publicKey = certificate.getPublicKey();
      // TODO Working with the public key...
      

      【讨论】:

        猜你喜欢
        • 2012-07-26
        • 2013-05-28
        • 1970-01-01
        • 2019-08-11
        • 1970-01-01
        • 1970-01-01
        • 2017-11-22
        • 2013-08-17
        • 1970-01-01
        相关资源
        最近更新 更多