Elist
Elist

Reputation: 5533

Java - generate machine specific encryption key

I'm writing a class that serializes a map of encrypted objects to a file, in order to maintain user login data etc.
The idea is to be able to always recover and decrypt the data using this class on the same machine, but not on other machines.
For this purpose (as suggested in this SO post and other articles) I am iterating over the Network Interfaces' hardware addresses, while using them to hash the default constant key:

byte[] key = getConstKey();
Enumeration<NetworkInterface> inters = networkInterface.getNetworkInterfaces();
while (inters.hasMoreElements()) {
    NetworkInterface inter = inters.nextElement();
    if (inter.getHardwareAddress() == null) {
      continue;
    }
    hashKeyAccordingToAddress(key, inter.getHardwareAddress());
}

This worked well and passed all my tests, until one day I took my laptop out the office...

Apparently, some network addresses have changed, or interfaces have been added / removed when I changed networks. My assumption was that only real hardware modifications will change the generated key. I guess I was wrong.

Is there a way to make this more robust, like, use only specific NetworkInterfaces that tends to be more stable? Or is there a better way to generate a machine unique-persistent key?

UPDATE: to be more specific, the issues begin when I connect to a VPN service from outside the office. Since some of the login details are used to connect to services over this VPN, my solution becomes useless..

Upvotes: 0

Views: 1410

Answers (1)

Jonas K&#246;ritz
Jonas K&#246;ritz

Reputation: 2644

You may use the Trusted Platform Module (TPM), most newer Systems come with one already available. See This Library for a possibly easy way to access the TPM. Store your unique key on the TPM.

Upvotes: 2

Related Questions