doudu5029 2018-02-13 22:23
浏览 199

将base64字符串转换为int以在Go中进行加密使用

I'm trying to do some simple cryptography using golang.

I have an RSA public key in form of base64 encoded modulo and exponent. I want to use that values to instantiate rsa.PublicKey struct.

Converting modulo base64 string to big.Int looks pretty straightforward for me.

Unexpectedly, I had a lot of trouble trying to convert base64 string to simple int (the exponent part of RSA key).

The best thing I've came up with:

package main

import (
        "encoding/base64"
        "fmt"
        "math/big"
)

func main() {
        e_data, _ := base64.RawURLEncoding.DecodeString("AQAB")

        e_big := new(big.Int)
        e_big.SetBytes(e_data)
        e := int(e_big.Int64())

        // Finally I have an int here to use it in rsa.PublicKey struct
        fmt.Println(e)
}

Is there any better, more simple way to convert base64 string to int?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 FPGA-SRIO初始化失败
    • ¥15 MapReduce实现倒排索引失败
    • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
    • ¥15 找一位技术过硬的游戏pj程序员
    • ¥15 matlab生成电测深三层曲线模型代码
    • ¥50 随机森林与房贷信用风险模型
    • ¥50 buildozer打包kivy app失败
    • ¥30 在vs2022里运行python代码
    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题