Search code examples
javaencryptionuniqueidentifierdrmcpuid

How to get cpu-id in java?


I want to create an encryption with java.
Is there anyway to get CPU Id or anything that be unique in PC such as BIOS or ...

for example System.getCpuId(); it is just an example 😉

Thanks a lot ...


Solution

  • if you need unique id you can use UUID :

    import java.util.UUID;
    
    public class GenerateUUID {
    
    
          public static final void main(String... aArgs){
            //generate random UUIDs
            UUID idOne = UUID.randomUUID();
            UUID idTwo = UUID.randomUUID();
            log("UUID One: " + idOne);
            log("UUID Two: " + idTwo);
          }
    
          private static void log(Object aObject){
            System.out.println( String.valueOf(aObject) );
          }
        } 
    

    Example run :

    >java -cp . GenerateUUID
    UUID One: 067e6162-3b6f-4ae2-a171-2470b63dff00 
    UUID Two: 54947df8-0e9e-4471-a2f9-9af509fb5889