Java Android:在电子邮件应用程序中实现基本加密

Java Android:在电子邮件应用程序中实现基本加密,java,android,encryption,Java,Android,Encryption,我目前正在构建一个电子邮件应用程序,作为其中的一部分,我需要实现一些基本的电子邮件加密,以确保它们安全地发送和接收。感谢您的任何帮助,因为我对android或java加密知之甚少。使用以下功能: private static final String ALGORITHM = "AES"; private static final byte[] keyValue = new byte[] { 'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e'

我目前正在构建一个电子邮件应用程序,作为其中的一部分,我需要实现一些基本的电子邮件加密,以确保它们安全地发送和接收。感谢您的任何帮助,因为我对android或java加密知之甚少。

使用以下功能:

 private static final String ALGORITHM = "AES";
 private static final byte[] keyValue =
        new byte[] { 'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' };


 public String encrypt(String valueToEnc) throws Exception {
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encValue = c.doFinal(valueToEnc.getBytes());
    // String encryptedValue = new Base64.encoder();

    return Base64.encodeToString(encValue, Base64.DEFAULT);
}

public String decrypt(String encryptedValue) throws Exception {
    Key key = generateKey();
    Cipher c = Cipher.getInstance(ALGORITHM);
    c.init(Cipher.DECRYPT_MODE, key);
    //byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedValue);
    byte[] decordedValue = Base64.decode(encryptedValue, Base64.DEFAULT);

    byte[] decValue = c.doFinal(decordedValue);
    String decryptedValue = new String(decValue);
    return decryptedValue;
}

谢谢Federico,我调用它时会把它放在一个单独的java文件中吗?好的,谢谢,如果你有时间,你能解释一下它是如何工作的,这样我就不会盲目地使用我不懂的东西了。