Java未命名的Elliptic Curves

时间:2017-12-19 13:22:27

标签: java cryptography elliptic-curve ecdsa

我正在尝试验证椭圆曲线签名。我有所有的曲线参数,我使用sun.security.ec.ECPublicKeyImpl来构造publickey。但我需要使用的曲线不是太阳安全的命名曲线之一。在ECPublicKeyImpl的构造函数中,我得到“不支持曲线”错误。 虽然我给出了EC的所有参数,为什么sun提供者需要曲线命名?我可以在sun提供程序中定义我的命名曲线吗? 我正在使用的代码:

    @Test
    public void testCreateECPublicKey() throws  Exception
    {
        BigInteger p = new BigInteger(1, StringUtil.hexToByte("A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377"));
        ECField field = new ECFieldFp(p);
        BigInteger a = new BigInteger(1, StringUtil.hexToByte("7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9"));
        BigInteger b = new BigInteger(1, StringUtil.hexToByte("26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6"));
        EllipticCurve curve = new EllipticCurve(field, a, b);

        ECPoint pointG = getECPoint(StringUtil.hexToByte("048BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997"));
        BigInteger n = new BigInteger(1, StringUtil.hexToByte("A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7"));
        int h = (int) 01;

        ECParameterSpec parameterSpec = new ECParameterSpec(curve, pointG, n, h);

        ECPoint publicPoint = getECPoint(StringUtil.hexToByte("041FED84C3FFDFABFBA36A754D6258ABD33F949CDC1D28AD9648337075484648E49CC230B8A4DD95AE44CBB78178A0C7137C66EA603D0549701997685DD4265F41"));
        ECPublicKeyImpl publicKey = new ECPublicKeyImpl(publicPoint, parameterSpec);
    }

    public ECPoint getECPoint(byte [] xAndy) throws ESYAException
    {
        if(xAndy[0] != 0x04)
            throw new ESYAException("Only uncompressed EC Point is supported!");

        int axisLen = (xAndy.length - 1) / 2;

        byte [] xBytes = Arrays.copyOfRange(xAndy, 1, 1 + axisLen);
        byte [] yBytes = Arrays.copyOfRange(xAndy, 1 + axisLen, 1 + axisLen + axisLen);

        return new ECPoint(new BigInteger(1, xBytes), new BigInteger(1, yBytes));
    }

0 个答案:

没有答案