can you help me te Seardh (Cti+1) File Edit View Navigate Source Refactor Run De
ID: 3735562 • Letter: C
Question
can you help me
te Seardh (Cti+1) File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Help PPE | . [ d DecodePage aa x TextEncryption awa Basiclava 1package Code: DNSClentserverApp ntro 0peratons Lossless DBEvaluater 3| import javax.crypto.Cipher; 4import javax.erypto.spec.Secretkeyspec: 5| L mport java.security.Key; 6 pubiic elass TextEncryption // AESEncryption 7 public static byte encrypt(bytet data,String pass) throws Exception , mazeFirstTest nGram Parallel Play-Cent Key key new SecretKeySpec (pass.getBytes), "AES" Cipher c C1pher. getinstance ("AES"); c.init return e.doFinal (data) t (Cipher. ENCRYPT MODE, key): Play-Server 14 public static bytell decrypt(byte data, String pass) throws Exception RatingProject Regex Key key ew SecreckeySpec (pass.getBytesES C1pher c = C1pher. getInstance ("AES"); c.init (Cipher. DECRYPT MODE, key) return c.doFinal (data); Simple Network Applicason Stego Source Packages 20 Code ColorChannel.java EncodeType.java LS8Extraction.java LSBInsertionjava PasswordType.java Output- Stego (run) x TextEncryptionjava -Frames AboutPage.java AlertBox-Java 00:25:42 00:01:34 Search Resuts Stego (run) INS ) ] all ENG 5:18 PMExplanation / Answer
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
class TextEncryption
{
public static SecretKey getSecretKey() throws Exception
{
KeyGenerator gen = KeyGenerator.getInstance("AES");
gen.init(128);
SecretKey key = gen.generateKey();
return key;
}
public static byte[] encryptText(String text, SecretKey key) throws Exception
{
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.ENCRYPT_MODE, key);
byte[] byteCipherText = aesCipher.doFinal(text.getBytes());
return byteCipherText;
}
public static String decryptText(byte[] byteCipherText, SecretKey key) throws Exception
{
Cipher aesCipher = Cipher.getInstance("AES");
aesCipher.init(Cipher.DECRYPT_MODE, key);
byte[] bytePlainText = aesCipher.doFinal(byteCipherText);
return new String(bytePlainText);
}
public static void main(String args[] ) throws Exception
{
String plaintext = "Jack is jon";
SecretKey key = getSecretKey();
byte[] cipherText = encryptText(plaintext,key);
String decryptedText = decryptText(cipherText,key);
System.out.println("Plain Text : " + plaintext);
System.out.println("Secret key : "+ key);
System.out.println("Encrypted Text : " + cipherText );
System.out.println("Decrypted Text : "+ decryptedText);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.