encryption - Why does the Go function EncryptOAEP in the crypto/rsa library require a random io.Reader? -



encryption - Why does the Go function EncryptOAEP in the crypto/rsa library require a random io.Reader? -

i'm writing file server encrypts info on client side, sends info on tcp, , decrypts on server side using asymmetric rsa-oaep encryption. there 2 main functions have been trying use, take next arguments per documentation:

encryptoaep(hash hash.hash, random io.reader, pub *publickey, msg []byte, label []byte) (out []byte, err error) decryptoaep(hash hash.hash, random io.reader, priv *privatekey, ciphertext []byte, label []byte) (msg []byte, err error)

each requires random io.reader, , test file uses rand.reader crypto/rand. however, whenever encrypt message rand.reader on client side, message never decrypted on server side has separate instance of rand.reader.

what purpose of random io.reader? how can ensure encrypted message transferred , decrypted server? need transfer info rand.reader used client server message decrypted?

using rsa_test.go base of operations managed create little end end decryption program. informations provided hard tell error is, hope reading programme can find bug yourself. don't need provide reader in decryptoaep.

http://play.golang.org/p/7vvchjob7r

package main import ( "bytes" "crypto/rsa" "crypto/sha1" "log" "math/big" ) func main() { sha1 := sha1.new() n := new(big.int) d := new(big.int) rsa_modulus := "a8b3b284af8eb50b387034a860f146c4919f318763cd6c5598c8ae4811a1e0abc4c7e0b082d693a5e7fced675cf4668512772c0cbc64a742c6c630f533c8cc72f62ae833c40bf25842e984bb78bdbf97c0107d55bdb662f5c4e0fab9845cb5148ef7392dd3aaff93ae1e6b667bb3d4247616d4f5ba10d4cfd226de88d39f16fb" rsa_d := "53339cfdb79fc8466a655c7316aca85c55fd8f6dd898fdaf119517ef4f52e8fd8e258df93fee180fa0e4ab29693cd83b152a553d4ac4d1812b8b9fa5af0e7f55fe7304df41570926f3311f15c4d65a732c483116ee3d3d2d0af3549ad9bf7cbfb78ad884f84d5beb04724dc7369b31def37d0cf539e9cfcdd3de653729ead5d1" n.setstring(rsa_modulus, 16) d.setstring(rsa_d, 16) public := rsa.publickey{n, 65537} d.setstring(rsa_d, 16) private := new(rsa.privatekey) private.publickey = public private.d = d seed := []byte{0x18, 0xb7, 0x76, 0xea, 0x21, 0x06, 0x9d, 0x69, 0x77, 0x6a, 0x33, 0xe9, 0x6b, 0xad, 0x48, 0xe1, 0xdd, 0xa0, 0xa5, 0xef, } randomsource := bytes.newreader(seed) in := []byte("hello world") encrypted, err := rsa.encryptoaep(sha1, randomsource, &public, in, nil) if err != nil { log.println("error: %s", err) } plain, err := rsa.decryptoaep(sha1, nil, private, encrypted, nil) if err != nil { log.println("error: %s", err) } log.println(string(plain)) }

encryption tcp go cryptography rsa

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -