Browse Source

main eingefügt

featureCrypto
Christian Baltzer 5 years ago
parent
commit
96db15434d
  1. 14
      src/main/java/com/ugsbo/Crypto/Crypto_Logic.java
  2. 11
      src/main/java/com/ugsbo/Crypto/Payload.java
  3. 2
      src/test/java/com/ugsbo/Crypto/Crypt.java

14
src/main/java/com/ugsbo/Crypto/Crypto_Logic.java

@ -1,10 +1,22 @@
package com.ugsbo.Crypto;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
public class Crypto_Logic {
public static void main(String[] args) {
public static void main(String[] args) throws UnsupportedEncodingException, GeneralSecurityException {
// TODO Auto-generated method stub
String test = "Hallo, mein Name ist Christian";
Payload temp = new Payload();
temp.setOffen(test);
temp.setPassword("geheim");
temp.verschlüsseln();
System.out.println(temp.getVerschlüsselt());
temp.entschlüsseln();
System.out.println(temp.getOffen());
}
}

11
src/main/java/com/ugsbo/Crypto/Payload.java

@ -5,6 +5,7 @@ import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
@ -74,15 +75,15 @@ public class Payload {
cipher.init(Cipher.ENCRYPT_MODE, password);
byte[] encrypted = cipher.doFinal(offen.getBytes());
verschlüsselt = encrypted.toString();
verschlüsselt = Base64.getEncoder().encodeToString(encrypted);
}
public void entschlüsseln() throws NoSuchAlgorithmException, GeneralSecurityException {
byte[] text = verschlüsselt.getBytes();
byte[] text = Base64.getDecoder().decode(verschlüsselt);
Cipher cipher2 = Cipher.getInstance("AES");
cipher2.init(Cipher.DECRYPT_MODE, password);
byte[] cipherData2 = cipher2.doFinal(text);
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, password);
byte[] cipherData2 = cipher.doFinal(text);
offen = new String(cipherData2);
}

2
src/test/java/com/ugsbo/Crypto/Crypt.java

@ -53,8 +53,8 @@ public class Crypt {
try {
workingobjekt.setOffen(eingabe);
workingobjekt.setPassword(password);
workingobjekt.entschlüsseln();
workingobjekt.verschlüsseln();
workingobjekt.entschlüsseln();
} catch (GeneralSecurityException | UnsupportedEncodingException e) {
e.printStackTrace();
}

Loading…
Cancel
Save