Im creating a banking system for a university assignment. Basically I have been struggling with encrypting user data. Its a first year assignment (in a 3 year bachelor) please bear this in mind when commenting x)))
//The constructor sets the global veriable key to a user defined value.
//The method byteToString adds the byte[] to a string char by char.
/**
* Cant handle special characters.
* Encrypts by adding the key value to each byte in the given string.
* @param stringIn, string to be encrypted
* @return the string representation of the encrypted string.
*/
public String encrypt(String stringIn) {
byte[] arrayIn = stringIn.getBytes();
for(int i = 0;i<arrayIn.length;i++) {
arrayIn[i] =(byte) (arrayIn[i]+key);
}
System.out.println("encrypted**** "+byteToString(arrayIn));
return byteToString(arrayIn);
}
/**
* Cant handle special characters.
* Decrypts a encrypted string. Needs to be the same key value.
* @param stringIn, encrypted string to be decrypted
* @return Decrypted string
*/
public String decrypt(String stringIn) {
byte[] arrayIn = stringIn.getBytes();
for(int i = 0;i<arrayIn.length;i++) {
arrayIn[i] =(byte) (arrayIn[i]-key);
}
System.out.println("decrypted**** "+byteToString(arrayIn));
return byteToString(arrayIn);
}