Forgive my pool English. The server program is code by java, i need to send it a password to generate aes key.The password is a random bytes array. The server program use the password as random seed to generate a 128 bits AES key with SHA1PRNG algorithm. The same password with gen the same key. Now i am coding the client program with golang. How to generate the AES key with a random bytes array in golang?
-
1Why would you add the encryption to the client?Martin– Martin2018-12-19 04:17:54 +00:00Commented Dec 19, 2018 at 4:17
-
1did not get your question. I guess you are asking for this: stackoverflow.com/questions/10701874/…Paritosh Singh– Paritosh Singh2018-12-19 04:50:46 +00:00Commented Dec 19, 2018 at 4:50
-
1I need to communicate with server with AES .yutian– yutian2018-12-19 04:52:13 +00:00Commented Dec 19, 2018 at 4:52
-
crypto/rand.ReadPeter– Peter2018-12-19 07:29:42 +00:00Commented Dec 19, 2018 at 7:29
Add a comment
|
1 Answer
you can try the code below
func SHA1(data []byte) []byte {
h := sha1.New()
h.Write(data)
return h.Sum(nil)
}
func aesKeySecureRandom(keyword string) (key []byte) {
data := []byte(keyword)
hashs := SHA1(SHA1(data))
key = hashs[0:16]
return key
}
you can use java or golang to verify
example:
keyword:123456
plainText:abc111abc
key hex:6bb4837eb74329105ee4568dda7dc67e
key base64:a7SDfrdDKRBe5FaN2n3Gfg==
cipherText base64:7ke0HhU5KnkCaPBilYsMiw==