I'm trying to implement the javax.crypto
encryption between my apps (through intnets). I follow this (accepted answer): https://stackoverflow.com/questions/4319496/how-to-encrypt-and-decrypt-data-in-java .The problem is as I understood I need to have the same SecretKeySpec key
in both of my apps in order to encrypt/decrypt the data. I have no idea how to export it (as a String or anything) and then hardcode it in both of my apps.
How to export symmetric encryption key?
2.5k Views Asked by XorOrNor At
1
You can export a
SecretKey
using thegetEncoded()
method. This returns a byte array, which you could encode to a string, for example using base 64 encoding. TheSecretKeySpec
object can be recreated from this encoded byte array.Just to give you a better idea, not tested:
Initial generation and export
Import/re-creation