i trying encrypt password go's rsa package.
here have far:
package main import ( "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) // 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 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) // <- not right, need create modulus publickey_mod string , needs 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] \n[%x]\n", string(plain_text), encrypted) return nil }
i unable set publickey.n value big.int given string.
variable decoded["publickey_mod"]
looks this:
d3abcd8303f887e0c7b390e088f24a797fe7084555ffb8bce21f25edd1f0dd02f48743ebaec6beea6789ddc2ab51c7297a73957ac5cbee7f4f8281ef6f47edbdc83c366cddaf087802082be1620749754d05078f9ee4e71b4b6b5b3c6b999652f99f019b65468c632fc918c6840b63f801a49c5938f7bfceb8eb913222a568cb2fe2f3e90911c1eae9592f2811fd9e156068abe18540542647d13a70d73f6dc5363a68426c3f9b1ec20fb29bb6920d784df7724b31321a3cf9320cc657ca4044bb59ae4afc4497fec0dc032004183d5116f456a0c9a303e942eeea6635a4e00c8ded8d6eab67708682ac04fc18ab3ca1705c18e17da9c6f06e2a0fdc905c88e3
and variable decoded["publickey_mod"]
looks 010001
i trying encrypt password https://steamcommunity.com/.
i have encrypted exact method using php before class called math_biginteger , how made publickey , encrypted password:
$key = array( 'n' => new math_biginteger($curl->response->publickey_mod,16), 'e' => new math_biginteger($curl->response->publickey_exp,16) ); // define exponent define('crypt_rsa_exponent', 010001); // load key $rsa->loadkey($key) // set settings $rsa->setencryptionmode(crypt_rsa_encryption_pkcs1); $rsa->sethash('sha256'); // encrypt password $encrypted_password = base64_encode($rsa->encrypt($password));
help extremely appreciated, in advance.
decoded["publickey_mod"]
hex string, need convert big.int:
publickey.n, _ = new(big.int).setstring(decoded["publickey_mod"].(string), 16 /* = base 16 */) // json numbers float64 default unless use struct , force type publickey.e = int(decoded["publickey_exp"].(float64))
Comments
Post a Comment