ChaCha20/src/tech/loedige/Main.java
2020-10-18 21:40:18 +02:00

34 lines
1.3 KiB
Java

package tech.loedige;
import th_owl.hs.datensicherheit.util.Dump;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class Main {
public static void main(String[] args)
throws Exception {
byte[] key = Dump.hexString2byteArray("0102030405060708090A0B0C0D0E0F10");
SecretKey secretKey = new SecretKeySpec(key, "AES");
Cipher cipher= Cipher.getInstance("AES/CTR/NOPADDING");
byte[] ctr = Dump.hexString2byteArray("FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE");
IvParameterSpec iv = new IvParameterSpec(ctr);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
byte[] m = new byte[35];
byte[] c = cipher.doFinal(m);
System.out.println("AES-CTR-Verschlüsselung mit "+
"Cipher-Instanz vom Typ AES/CTR/NOPADDING:");
System.out.println(Dump.dump(c));
System.out.println();
KeyStreamGenerator_AES_CTR ksg= new KeyStreamGenerator_AES_CTR();
ksg.initState(key, ctr);
AdditiveStreamCipher.encrypt(ksg, m);
System.out.println("AES-CTR-Verschlüsselung mit "+ "KeyStreamGenerator_AES_CTR-Implementierung:");
System.out.println(Dump.dump(m));
System.out.println();
}
}