第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go - 如何從字符串設(shè)置 RSA 公鑰模數(shù)?

Go - 如何從字符串設(shè)置 RSA 公鑰模數(shù)?

Go
有只小跳蛙 2022-01-04 09:44:40
我正在嘗試使用 Go 的RSA包加密密碼。這是我到目前為止所擁有的:package mainimport (    "fmt"    "time"    "net/http"    "strconv"    "io/ioutil"    "encoding/json"    "errors"    "crypto/rsa"    "crypto/rand"    //"math/big")func main() {    if err := Login("username", "password"); err != nil {        fmt.Println(err)    }}func Login(username, password string) error {    doNotCache := strconv.FormatInt(time.Now().UnixNano() / int64(time.Millisecond), 10)    // Get RSA Key    resp, err := http.PostForm("https://steamcommunity.com/login/getrsakey/", map[string][]string{        "donotcache": {doNotCache},        "username": {username},    })    if err != nil {        return err    }    content, err := ioutil.ReadAll(resp.Body)    if err != nil {        return err    }    var decoded map[string]interface{}    err = json.Unmarshal(content, &decoded)    if err != nil {        return err    }    if decoded["success"] != true {        return errors.New("Failed to retrieve RSA key.")    }    // Set encryption variables    var privateKey *rsa.PrivateKey    var publicKey *rsa.PublicKey    var plain_text, encrypted []byte    plain_text = []byte(password)    // Generate Private Key    if privateKey, err = rsa.GenerateKey(rand.Reader, 1024); err != nil {        return err    }    privateKey.Precompute()    if err = privateKey.Validate(); err != nil {        return err    }    publicKey.N = decoded["publickey_mod"].(string) // <- This is not right, I need to create a modulus from the publickey_mod string and it needs to be of type big.Int    publicKey.E = decoded["publickey_exp"].(int)    encrypted, err = rsa.EncryptPKCS1v15(rand.Reader, publicKey, plain_text)    if err != nil {        return err    }    fmt.Printf("PKCS1 Encrypted [%s] to \n[%x]\n", string(plain_text), encrypted)    return nil}我無法從給定的字符串將 publicKey.N 值設(shè)置為 big.Int。和變量decoded["publickey_mod"]看起來像010001我正在嘗試為https://steamcommunity.com/加密此密碼。
查看完整描述

1 回答

?
動漫人物

TA貢獻1815條經(jīng)驗 獲得超10個贊

decoded["publickey_mod"] 是十六進制字符串,您需要將其轉(zhuǎn)換為 big.Int:


publicKey.N, _ = new(big.Int).SetString(decoded["publickey_mod"].(string), 16 /* = base 16 */)

// json numbers are float64 by default unless you use a struct and force a type

publicKey.E = int(decoded["publickey_exp"].(float64))


查看完整回答
反對 回復(fù) 2022-01-04
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號