java实现ase加密解密

1) 实现文件的加密、解密功能,使用AES算法
2) 计算文件的指纹,即SHA-1,SHA-256值

要有图形化界面,参考下图,求解!

第1个回答  推荐于2016-09-16

这个算法java SDK自带的额 参考代码如下:

/**解密 

 * @param content  待解密内容 

 * @param password 解密密钥 

 * @return 

 */  

public static byte[] decrypt(byte[] content, String password) {  

        try {  

                 KeyGenerator kgen = KeyGenerator.getInstance("AES");  

                 kgen.init(128, new SecureRandom(password.getBytes()));  

                 SecretKey secretKey = kgen.generateKey();  

                 byte[] enCodeFormat = secretKey.getEncoded();  

                 SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");              

                 Cipher cipher = Cipher.getInstance("AES");// 创建密码器  

                cipher.init(Cipher.DECRYPT_MODE, key);// 初始化  

                byte[] result = cipher.doFinal(content);  

                return result; // 加密  

        } catch (NoSuchAlgorithmException e) {  

                e.printStackTrace();  

        } catch (NoSuchPaddingException e) {  

                e.printStackTrace();  

        } catch (InvalidKeyException e) {  

                e.printStackTrace();  

        } catch (IllegalBlockSizeException e) {  

                e.printStackTrace();  

        } catch (BadPaddingException e) {  

                e.printStackTrace();  

        }  

        return null;  

}  



/** 

 * 加密 

 *  

 * @param content 需要加密的内容 

 * @param password  加密密码 

 * @return 

 */  

public static byte[] encrypt(String content, String password) {  

        try {             

                KeyGenerator kgen = KeyGenerator.getInstance("AES");  

                kgen.init(128, new SecureRandom(password.getBytes()));  

                SecretKey secretKey = kgen.generateKey();  

                byte[] enCodeFormat = secretKey.getEncoded();  

                SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES");  

                Cipher cipher = Cipher.getInstance("AES");// 创建密码器  

                byte[] byteContent = content.getBytes("utf-8");  

                cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化  

                byte[] result = cipher.doFinal(byteContent);  

                return result; // 加密  

        } catch (NoSuchAlgorithmException e) {  

                e.printStackTrace();  

        } catch (NoSuchPaddingException e) {  

                e.printStackTrace();  

        } catch (InvalidKeyException e) {  

                e.printStackTrace();  

        } catch (UnsupportedEncodingException e) {  

                e.printStackTrace();  

        } catch (IllegalBlockSizeException e) {  

                e.printStackTrace();  

        } catch (BadPaddingException e) {  

                e.printStackTrace();  

        }  

        return null;  

}  

http://blog.csdn.net/hbcui1984/article/details/5201247
图像界面的话就不说了

本回答被提问者和网友采纳
第2个回答  2014-01-03
你只知道算法,做这个有什么难点吗?