为了账号安全,请及时绑定邮箱和手机立即绑定

自定义 Java 公钥生成(比特币)

自定义 Java 公钥生成(比特币)

喵喔喔 2023-03-31 10:10:55
私钥是随机生成的,不与任何钱包关联。我想为比特币准备公钥生成的自定义(简单)实现。然而,经过几次尝试,我的结果是不正确的。我将它们与在线生成器进行了比较。我发现我使用了除法而不是 modinv。不幸的是,在将 division 更改为 modinv 之后,我得到了“java.lang.ArithmeticException: BigInteger not invertible.”。我厌倦了关注https://www.mobilefish.com/services/cryptocurrency/cryptocurrency.html#refProdedure和https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication你能帮我认出我在哪里做错了吗?public class ECDSAUtils {    private static final CurvePoint G = new CurvePoint(new BigInteger("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16), new BigInteger("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16));    private static CurvePoint zero;    private static BigInteger base;    private static final BigInteger three = new BigInteger("3", 10);    public static void main(String[] args){        ECDSAUtils e = new ECDSAUtils();        BigInteger privateKey = new BigInteger("fdc668381ab251673ef8552851a2c7cf346a6e09ea86be0f55a94d2a12253557", 16);        CurvePoint r = e.mult(G, privateKey);        System.out.println(r.x.toString(16).toUpperCase() + " " + r.y.toString(16).toUpperCase());    }    public ECDSAUtils(){        zero = new CurvePoint(new BigInteger("0", 16), new BigInteger("0", 16));        base = new BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16);    }    public static CurvePoint add(CurvePoint p, CurvePoint q){        CurvePoint result = null;        if (p.equals(zero)){            result = q;        } else if (q.equals(zero)){            result = p;        } else {            BigInteger lambda = q.y.subtract(p.y).modInverse(q.x.subtract(p.x)).mod(base);            BigInteger x = lambda.multiply(lambda).subtract(p.x).subtract(q.x).mod(base);            BigInteger y = lambda.multiply(p.x.subtract(x)).subtract(p.y).mod(base);            result = new CurvePoint(x, y);        }        return result;  
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 82 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信