This feature is used to convert an original character into an unreadable character.
Most of the programs use this feature to encrypt and decrypt a user name and password so that if there is unauthorized person access to your restricted database, they cannot read it directly because it is encrypted. To make this visible to the human eye, they need to decrypt it so that it is converted to the original character and readable by a human.There are two different types of encryption, Asymmetric and Symmetric encryption. The following encryption is supported by Java. You can search it on the web to further understanding about the Asymmetric and Symmetric encryption.
This topic shows only the basic encryption in Java programming. You can copy the code and use it in your Java program for educational and practice purposes. We are not 100% sure about the protection and accuracy of this encryption type. Use it with your own risk.
Step 1. Create a class inside your project and insert the following codes below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String encrypt(String key) { | |
String result = ""; | |
int l = key.length(); | |
char ch; | |
for(int i = 0; i < l; i++){ | |
ch = key.charAt(i); | |
ch += 10; | |
result += ch; | |
} | |
return result; | |
} | |
public static String decrypt(String key) { | |
String result = ""; | |
int l = key.length(); | |
char ch; | |
for(int i = 0; i < l; i++){ | |
ch = key.charAt(i); | |
ch -= 10; | |
result += ch; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//encrypt character | |
String pass = pass_security.encrypt(password.getText()); | |
newPassword.setText(pass); | |
//decrypt character | |
String pass = pass_security.decrypt(password.getText()); | |
newPassword.setText(pass); |
0 Comments