Skip to content
Snippets Groups Projects
Select Git revision
  • f3c6bf2e36f40e831a97be7fee35e11674f04beb
  • master default protected
  • hai
  • isaac
  • CheHao
  • Eldar
  • mpriymak
  • master-before-merging-with-hai
  • master-before-merging-with-isaac
  • rmi-working-before-merging-with-isaac
  • all-code-merged-by-hai-v1
11 results

ChatScreen.java

Blame
  • EncryptDecrypt.java 1.81 KiB
    package remote;
    
    import javax.crypto.*;
    import java.io.IOException;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    
    public class EncryptDecrypt {
        public static String decryptString (SealedObject sealedObject, SecretKey key){
    
            String nonSealedString ="";
            Cipher cipher = null;
            try {
                cipher = Cipher.getInstance("AES");
                cipher.init(Cipher.DECRYPT_MODE,key);
                nonSealedString = (String)sealedObject.getObject(cipher);
    
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (NoSuchPaddingException e) {
                e.printStackTrace();
            } catch (InvalidKeyException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IllegalBlockSizeException e) {
                e.printStackTrace();
            } catch (BadPaddingException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return nonSealedString;
    
        }
        public static SealedObject encryptString (String string, SecretKey key){
            SealedObject sealedObject = null;
    
            Cipher cipher = null;
            try {
                cipher = Cipher.getInstance("AES");
                cipher.init(Cipher.ENCRYPT_MODE,key);
                sealedObject = new SealedObject(string,cipher);
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (NoSuchPaddingException e) {
                e.printStackTrace();
            } catch (IllegalBlockSizeException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (InvalidKeyException e) {
                e.printStackTrace();
            }
            return sealedObject;
    
    
        }
    }