Click here to Skip to main content
15,668,126 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone,

Please do the needful on this:

Write a string in encrypted way in Windows registry using java. and have options to store multiple values in windows registry



What I have tried:

I have tried with java.util.prefs.Preferences, but it did not work.
Updated 3-Sep-16 19:10pm
Richard MacCutchan 2-Sep-16 3:22am    
What does "it did not work." mean?

Bad question: Your question is multiple questions

- How to encrypt a string ?
- implying: How to decrypt a string ?
- implying: Which encrypting/decrypting method ?
- How to save a string in registry ?
- implying: How to retrieve a string in registry ?
- How to save multiple values in registry ?

Tell what is your problem, show your code.
Share this answer
Arjun2016 2-Sep-16 1:59am    
My questions are : How to save a string in registry and i need to save multiple values in registry.
Encrypt/Decrypt a string is working fine with my sample code.

I have tried with this code:
Share this answer
Mehdi Gholam 2-Sep-16 1:50am    
Maciej Los 2-Sep-16 1:51am    
Thank you, Mehdi.
Hello Guys,

i have worked on this sample application using JNA jar, it's working. But i need to achieve the same without using external jar "Create a registry key and write the entries to registry". Any help on this!

here is my code:
import com.sun.jna.platform.win32.Advapi32Util;
import static com.sun.jna.platform.win32.WinReg.HKEY_CURRENT_USER;
import java.util.Scanner;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class Test {
	private static String encryptionKey;
	public Test(String encryptionKey)
        Test.encryptionKey = encryptionKey;
	private static void SetEncryptiontKey(String string) {
		// TODO Auto-generated method stub
		Test.encryptionKey = string;
    public String encrypt(String plainText) throws Exception
        Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
        byte[] encryptedBytes = cipher.doFinal(plainText.getBytes());

        return Base64.encode(encryptedBytes);

    private Cipher getCipher(int cipherMode)
            throws Exception
        String encryptionAlgorithm = "AES";
        SecretKeySpec keySpecification = new SecretKeySpec(
                encryptionKey.getBytes("UTF-8"), encryptionAlgorithm);
        Cipher cipher = Cipher.getInstance(encryptionAlgorithm);
        cipher.init(cipherMode, keySpecification);

        return cipher;
    public static void main(String[] args) {
    	Scanner in = new Scanner(;
    	System.out.println("Enter User Name\n");
    	String Username = in.nextLine();
    	System.out.println("Enter Password\n");
    	String Password = in.nextLine();
    	Test advancedEncryptionStandard = new Test(
    	String cipherText = null;
		try {
			cipherText = advancedEncryptionStandard.encrypt(Password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
    	Advapi32Util.registryCreateKey(HKEY_CURRENT_USER, "Software\\Dell Configuration");
       // System.out.println(Advapi32Util.registryKeyExists(HKEY_CURRENT_USER, "Software"));
            (HKEY_CURRENT_USER, "Software\\Dell Configuration", "Username", Username);
        (HKEY_CURRENT_USER, "Software\\Dell Configuration", "Password", cipherText);

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900