Commit a5c00a27 authored by yazan.halloul's avatar yazan.halloul

build important classes for implement system

parent bf197cb7
package benefit_classes;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
public class DESAlgorithm {
private SecretKey secretKey;
public DESAlgorithm(String encodedKey) { // The common encodedKey is: fzI0SlHWAfc=
// decode the base64 encoded string
byte[] decodedKey = Base64.getDecoder().decode(encodedKey);
// rebuild key using SecretKeySpec
secretKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "DES");
}
public String encryption(String text) throws NoSuchPaddingException, NoSuchAlgorithmException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
Cipher desCipher = Cipher.getInstance("DES");
desCipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] textEncrypted = desCipher.doFinal(text.getBytes("UTF-8"));
return Base64.getEncoder().encodeToString(textEncrypted);
}
public String decryption(String text) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException {
Cipher desCipher = Cipher.getInstance("DES");
desCipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] textDecrypted = desCipher.doFinal(Base64.getDecoder().decode(text));
return new String(textDecrypted, "UTF-8");
}
}
package benefit_classes;
public class LineSequence {
private String line;
private int sequence;
public LineSequence(String line, int sequence) {
this.line = line;
this.sequence = sequence;
}
public void setLine(String line) {
this.line = line;
}
public String getLine() {
return line;
}
public int getSequence() {
return sequence;
}
}
package benefit_classes;
import java.util.Comparator;
public class LineSequenceComparator implements Comparator<LineSequence> {
@Override
public int compare(LineSequence s1, LineSequence s2) {
if (s1.getSequence() > s2.getSequence())
return 1;
else if (s1.getSequence() < s2.getSequence())
return -1;
return 0;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment