dongwen3093 2016-05-28 17:50
浏览 184
已采纳

声明类型* big.Int溢出常量golang

Generating a keypair using the crypto/rsa package is trivial, but declaring it yourself is a pain.

I'm trying to declare a variable of type rsa.PublicKey, which is defined as:

type PublicKey struct {
        N *big.Int // modulus
        E int      // public exponent
}

I've tried a hundred and three methods, but my code currently looks like:

PublicKey := new(rsa.PublicKey)

PublicKey.N = 816296297763124917516388440338759500423535395290623239231731567955308683122890408110917894172120047293936355563865250296188045077627313515614945465389856882915690164742049821466713295090362914686221827012330520911241180940331170800129566133563943306086709509374426793735798983196271063876215936717347200817820685489907456621846519078704338901417077754153251584919148131668369473222078960469749879767829241702858598298315759777245767370065542249841401685747514693845945420663931515035586797756896017462499826100826469085345198490755785708882569397123671313993933597159332140624225622926365258472081852103795720495728779491860405409429756519754432759030127289255409541378096471189783136441306888685144178712329637014132885623358066824356187044819578205172698506597932578231190886063535262514544569054747443504586895362356519252402500104155389876467086444850150261677007183689594568339805440756958346151465691221654766132846717117978938197863452998630570321897641091974200100764524637808876854013287571133384735164135339783262769321526997252096927500094807456840263828514476848496064212933462545940124330314474126636272733109787671957872657823289210871868354885730638093964892263227561606744192311648252923260065974092128743259979645799

PublicKey.E = 65537

I get this error:

./main.go:21: constant too large: 816296297763124917516388440338759500423535395290623239231731567955308683122890408110917894172120047293936355563865250296188045077627313515614945465389856882915690164742049821466713295090362914686221827012330520911241180940331170800129566133563943306086709509374426793735798983196271063876215936717347200817820685489907456621846519078704338901417077754153251584919148131668369473222078960469749879767829241702858598298315759777245767370065542249841401685747514693845945420663931515035586797756896017462499826100826469085345198490755785708882569397123671313993933597159332140624225622926365258472081852103795720495728779491860405409429756519754432759030127289255409541378096471189783136441306888685144178712329637014132885623358066824356187044819578205172698506597932578231190886063535262514544569054747443504586895362356519252402500104155389876467086444850150261677007183689594568339805440756958346151465691221654766132846717117978938197863452998630570321897641091974200100764524637808876854013287571133384735164135339783262769321526997252096927500094807456840263828514476848496064212933462545940124330314474126636272733109787671957872657823289210871868354885730638093964892263227561606744192311648252923260065974092128743259979645799
./main.go:21: overflow in constant
./main.go:21: cannot use 0 (type int) as type *big.Int in assignment

Any help?

  • 写回答

2条回答 默认 最新

  • douhuang2282 2016-05-28 18:24
    关注

    The problem is that Go interprets your literal value as an int. But, it does not really fit into 32 bits, so it fails. However, you can set the value of a big.Int after its creation:

    PublicKey.N = big.NewInt(0)
    PublicKey.N.SetBytes([]byte("8162962977631249175163884403387595004235353952981629629776312491751638844033875950042353539529"))
    fmt.Println(N)
    // 8162962977631249175163884403387595004235353952981629629776312491751638844033875950042353539529
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。