add byte methods to RawKey
This commit is contained in:
parent
fb459defea
commit
2f47747045
1 changed files with 19 additions and 11 deletions
|
@ -45,7 +45,20 @@ public class RawKey extends Key {
|
|||
* @return encrypted string
|
||||
*/
|
||||
public String encryptString(String s) {
|
||||
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
|
||||
return new String(encryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a string
|
||||
* @param s string to decrypt
|
||||
* @return decrypted string
|
||||
*/
|
||||
public String decryptString(String s) {
|
||||
return new String(decryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
public byte[] encryptBytes(byte[] bytes) {
|
||||
bytes = bytes.clone();
|
||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
||||
int len = bytes.length;
|
||||
int p = eb.length;
|
||||
|
@ -55,16 +68,11 @@ public class RawKey extends Key {
|
|||
bytes[idx] = (byte) ((int) bytes[idx] + (int) eb[j]);
|
||||
}
|
||||
}
|
||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a string
|
||||
* @param s string to decrypt
|
||||
* @return decrypted string
|
||||
*/
|
||||
public String decryptString(String s) {
|
||||
byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
|
||||
public byte[] decryptBytes(byte[] bytes) {
|
||||
bytes = bytes.clone();
|
||||
byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1);
|
||||
int len = bytes.length;
|
||||
int p = eb.length;
|
||||
|
@ -74,7 +82,7 @@ public class RawKey extends Key {
|
|||
bytes[idx] = (byte) ((int) bytes[idx] - (int) eb[j]);
|
||||
}
|
||||
}
|
||||
return new String(bytes, StandardCharsets.ISO_8859_1);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue