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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题