尚未执行:DSA公钥 [英] Not implemented yet: DSA public key

查看:266
本文介绍了尚未执行:DSA公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个服务器和一个Android客户端应用程序。在Android客户端发送测量到服务器。为了保证数据的完整性,数字签名被附加到每个测量

I'm writing both a server and an Android client application. The Android client sends measurements to the server. In order to ensure the data integrity, a digital signature is appended to each measurement.

由于我所需要的一切是GSON兼容,存储公钥本身是不可能的。我存储的G,P,Q和Y因子来代替。

Since I need everything to be Gson-compatible, storing the public key itself is not possible. I'm storing the G, P, Q and Y factors instead.

下面是从请求类的一个片段:

Here's a snippet from the request class:

    public PublicKey getPublicKey() {
    try {
        DSAPublicKeySpec keySpec = new DSAPublicKeySpec(publicKeyY, publicKeyP,
                                                        publicKeyQ, publicKeyG);
        KeyFactory fact = KeyFactory.getInstance("DSA");
        PublicKey pubKey = fact.generatePublic(keySpec); // A
        return pubKey;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

public void setPublicKey(PublicKey publicKey) {
    try {
        KeyFactory fact = KeyFactory.getInstance("DSA");
        DSAPublicKeySpec pub = fact.getKeySpec(publicKey, DSAPublicKeySpec.class); // B
        publicKeyG = pub.getG();
        publicKeyP = pub.getP();
        publicKeyQ = pub.getQ();
        publicKeyY = pub.getY();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

构造利用了setPublicKey-方法。当我在客户端创建这样的请求,并将其在一个异常发送到服务器,两者结果

The constructor makes use of the setPublicKey-method. When I create such request on the client side and send it to the server, both result in an exception.

在客户端:

 java.lang.RuntimeException: not implemented yet DSA Public Key
             y: 2f9286201b266f38d682e99814612f7d37c575d3a210de114bdf02092f4a835109f28a590cfc568bb6525d59b8275fe791f3ddf20e85df44fd2e8622289f6dbc27c73d31d1769feae19573df22a9ca8ef80a9f7230b0b4a2671cc03fdb2788b55b4e9a68a7a5a93a214cc5aa39ccb5155a13354870d45a38760a80fd34333073
  class java.security.spec.DSAPublicKeySpec
    at org.bouncycastle.jce.provider.JDKKeyFactory.engineGetKeySpec(JDKKeyFactory.java:148)
    at java.security.KeyFactory.getKeySpec(KeyFactory.java:210)

在我标记为B规则的堆栈跟踪点,接下来的事情

Next thing in the stack trace points at the rule I marked as B

在服务器上:

java.lang.NullPointerException
    at sun.security.provider.DSAPublicKey.<init>(DSAPublicKey.java:74)
    at sun.security.provider.DSAPublicKeyImpl.<init>(DSAPublicKeyImpl.java:46)
    at sun.security.provider.DSAKeyFactory.engineGeneratePublic(DSAKeyFactory.java:86)
    at java.security.KeyFactory.generatePublic(KeyFactory.java:304)
    at sensserve.protocol.StartSessionRequest.getPublicKey(StartSessionRequest.java:66)

Nextly指向规则的。

Nextly pointing to the rule A.

我绝对不知道我做错了什么以及这些消息的意思。我该如何解决这些?任何人谁可以告诉我什么,我做错了吗?

I absolutely have no clue what I did wrong and what these messages mean. How can I solve these? Anyone who can tell me what I'm doing wrong?

非常感谢。

推荐答案

您应该能够公开密钥存储在Base64的途中从codeD,仍然可以得到有效的JSON。你应该能够到DSAPublicKeySpec 直接使用,而无需调用 getKeySpec()这显然不是在充气城堡(Android的JCE实现供应商)。不知道你为什么在服务器上获得NPE,也许格式错误。顺便说一句,它可能会更容易,如果你正在处理一个单一的供应商,所以你可能想在服务器上使用充气城堡为好。

You should be able to store the public key in Base64 encoded from and still get valid JSON. You should be able to use DSAPublicKeySpec directly without calling getKeySpec() which apparently is not implemented in Bouncy Castle (Android's JCE provider). Not sure why you are getting NPE on the server, maybe wrong format. BTW, it will probably be easier if you are dealing with a single provider, so you might want to use Bouncy Castle on the server as well.

这篇关于尚未执行:DSA公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆