1

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?

4
  • 1
    Why would you add the encryption to the client? Commented Dec 19, 2018 at 4:17
  • 1
    did not get your question. I guess you are asking for this: stackoverflow.com/questions/10701874/… Commented Dec 19, 2018 at 4:50
  • 1
    I need to communicate with server with AES . Commented Dec 19, 2018 at 4:52
  • crypto/rand.Read Commented Dec 19, 2018 at 7:29

1 Answer 1

0

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==

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.