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?