-1

I'm using an AES key of type cipher.Block generated by using crypto/aes package with below func:

aesBlock, err := aes.NewCipher(randKey)

I'm using this to encrypt a particular set of data but afterward I want to encrypt aesBlock itself with a Public Key, so that I can store and later decrypt with the asymmetric Private Key. However, I'm having a tough time finding the best way to encrypt aesBlock. Obviously this needs to be reversible so that I can use it to decrypt the previously mentioned data.

The func EncryptOAEP from crypto/aes seems like a good fit, as it takes a *PublicKey, however the msg parameter is of type []byte and my AES key is of type cipher.Block. Not sure a direct conversion is possible or even a good idea.

Any ideas?

Devin
  • 1,011
  • 2
  • 14
  • 30
  • Why would you try to encrypt `aesBlock` itself? Just encrypt and store `randKey` and create a new `aesBlock` as needed. – Adrian Sep 28 '17 at 15:53
  • Will using `randKey` recreate the same `aesBlock`? I guess I thought that this was more of a salt to help randomize `aesBlock` further. – Devin Sep 28 '17 at 15:58
  • Welp, you are correct - I just tested. I can't believe I didn't realize that. Thanks for shedding light. – Devin Sep 28 '17 at 16:05

1 Answers1

0

As Adrian pointed out in the comments, the solution is simpler than I thought. All you need to do is encrypt and store the randKey. Regenerating the aesBlock with decrypted randKey produces the same results.

Devin
  • 1,011
  • 2
  • 14
  • 30