精华内容
下载资源
问答
  • aes java源码AES AES加密过程的Java源代码和新的加密算法KIASU。 仅用于加密
  • java源码AESCipher-Java Java AES 加密 将此代码用于Android和Java 后端以及iOS可以让您准确地使用 AES 加密和解密。 加密: // For String public static String aesEncryptString(String content, String key) // ...
  • aes java 源码
  • java源码Whitebox-crypto-AES-java 白盒加密 AES 实现。 该存储库包含由等人引入的完整白盒 -128 方案的 Java 实现。 它实现/使用输入/输出编码、混合双射、外部编码。 实现代码包含 Chow 的白盒 AES 方案实例生成器...
  • java源码AESCipher-iOS Objective-C 的 AES 加密 将此代码用于iOS以及Android和Java 后端,您可以使用 AES 准确地加密和解密。 用 C 风格编码只是为了安全。 加密: // For String NSString * aesEncryptString...
  • aes java 源码
  • aes java 源码
  • AESjava实现

    2017-12-27 20:50:29
    密码学作业之一,辛辛苦苦实现的哎。网上的搜到的AES还是DES的S盒有个地方是不一样的。同学找了半天才找出来。有点不太记得了。几个月之前写的,供大家参考学习。环境就是eclipse
  • AESjava最最底层的代码实现,舍不得拿出来都,嫌贵爱要不要
  • java源码java-aes-crypto 这个 AES 库非常简单,仅适用于 Android。 对于跨平台加密系统,请使用 . 它适用于浏览器的 Android、iOS 和 JavaScript,以及 Node、Ruby、Python、Java 和 Go 等后端系统。 Java-AES-...
  • AES java源码

    2012-07-22 10:45:18
    自己动手写的AES算法 希望对大家有帮助 相互指教 相互学习
  • aes java 源码 This repository is a wechat springmvc demo based on WxJava 本仓库的项目是一个基 于**** 的springmvc Demo. 新手遇到问题,请务必先阅读的常见问题部分,可以少走很多弯路,节省不少时间。 本项目...
  • rsa des java 混合加密解密
  • aes java源码不再维护 HTML加密器 用Java开发的加密和解密应用程序。 该应用程序使用多种算法来加密和解密HTML源代码: 河豚 AES 茶 兔子 马克4 转义/逃生功能 除了加密和解密功能,该应用程序还返回网站的源代码。 ...
  • java版RAS加密签名验证实现, Md5加密实现, AES加密实现
  • AESJAVA实现(源码)___128、196、254位key都可以使用,调用其中函数设置三种长度的key.
  • AES JAVA平台版

    2015-03-11 14:30:05
    废话不多说了,请看代码把。...import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.

    废话不多说了,请看代码把。


    package base_crypt;
    
    import java.security.InvalidAlgorithmParameterException;
    import java.security.InvalidKeyException;
    import java.security.NoSuchAlgorithmException;
    
    import javax.crypto.BadPaddingException;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.NoSuchPaddingException;
    import javax.crypto.spec.IvParameterSpec;
    import javax.crypto.spec.SecretKeySpec;
    
    public class base_crypt {
    
    	/*********************************************
    	 * ecb_base_encrypt("AES/ECB/PKCS5Padding","AES",s_buf,p_pass);
    	 * @throws NoSuchPaddingException 
    	 * @throws NoSuchAlgorithmException 
    	 * @throws InvalidKeyException 
    	 * @throws BadPaddingException 
    	 * @throws IllegalBlockSizeException 
    	 *********************************************/
    	protected static byte[] ecb_base_encrypt(String p_formation,String p_algorithm,byte[] s_buf,byte[] p_pass) {
    		try{
    			Cipher cipher = Cipher.getInstance(p_formation);
    			SecretKeySpec keyspec = new SecretKeySpec(p_pass, p_algorithm);
    			cipher.init(Cipher.ENCRYPT_MODE,keyspec);
    			byte[] d_buf = cipher.doFinal(s_buf);
    			return d_buf;
    		} catch (InvalidKeyException | NoSuchAlgorithmException
    				| NoSuchPaddingException | IllegalBlockSizeException
    				| BadPaddingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	/*********************************************
    	 * ecb_base_decrypt("AES/ECB/PKCS5Padding","AES",s_buf,p_pass);
    	 * @throws NoSuchPaddingException 
    	 * @throws NoSuchAlgorithmException 
    	 * @throws InvalidKeyException 
    	 * @throws BadPaddingException 
    	 * @throws IllegalBlockSizeException 
    	 *********************************************/
    	protected static byte[] ecb_base_decrypt(String p_formation,String p_algorithm,byte[] s_buf,byte[] p_pass) {
    		
    		try{
    			Cipher cipher = Cipher.getInstance(p_formation);
    			SecretKeySpec keyspec = new SecretKeySpec(p_pass, p_algorithm);
    			cipher.init(Cipher.DECRYPT_MODE,keyspec);
    			byte[] d_buf = cipher.doFinal(s_buf);
    			return d_buf;
    		} catch (InvalidKeyException | NoSuchAlgorithmException
    				| NoSuchPaddingException | IllegalBlockSizeException
    				| BadPaddingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	/*********************************************
    	 * base_encrypt("AES/CBC/PKCS5Padding","AES",s_buf,p_pass,p_iv);
    	 * @throws NoSuchPaddingException 
    	 * @throws NoSuchAlgorithmException 
    	 * @throws InvalidKeyException 
    	 * @throws BadPaddingException 
    	 * @throws IllegalBlockSizeException 
    	 *********************************************/
    	protected static byte[] base_encrypt(String p_formation,String p_algorithm,byte[] s_buf,byte[] p_pass,byte[] p_iv) {
    		
    		try{
    			Cipher cipher = Cipher.getInstance(p_formation);
    			SecretKeySpec keyspec = new SecretKeySpec(p_pass, p_algorithm);
    			IvParameterSpec iv = new IvParameterSpec(p_iv);
    			cipher.init(Cipher.ENCRYPT_MODE,keyspec,iv);
    			byte[] d_buf = cipher.doFinal(s_buf);
    			return d_buf;
    		} catch (InvalidKeyException | NoSuchAlgorithmException
    				| NoSuchPaddingException | IllegalBlockSizeException
    				| BadPaddingException | InvalidAlgorithmParameterException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	/*********************************************
    	 * base_decrypt("AES/CBC/PKCS5Padding","AES",s_buf,p_pass,p_iv);
    	 * @throws NoSuchPaddingException 
    	 * @throws NoSuchAlgorithmException 
    	 * @throws InvalidKeyException 
    	 * @throws BadPaddingException 
    	 * @throws IllegalBlockSizeException 
    	 *********************************************/
    	protected static byte[] base_decrypt(String p_formation,String p_algorithm,byte[] s_buf,byte[] p_pass,byte[] p_iv){
    		try{
    			Cipher cipher = Cipher.getInstance(p_formation);
    			SecretKeySpec keyspec = new SecretKeySpec(p_pass, p_algorithm);
    			IvParameterSpec iv = new IvParameterSpec(p_iv);
    			cipher.init(Cipher.DECRYPT_MODE,keyspec,iv);
    			byte[] d_buf = cipher.doFinal(s_buf);
    			return d_buf;
    		} catch (InvalidKeyException | NoSuchAlgorithmException
    				| NoSuchPaddingException | IllegalBlockSizeException
    				| BadPaddingException | InvalidAlgorithmParameterException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    }
    


    package base_crypt;
    
    public class base_aes extends base_crypt{
    	
    	/* this class just provide the interface that crypt algorithm which paddinged with PKCS5Padding.*/
    	
    	private static String aes_mode_ecb_pkcs5 = "AES/ECB/PKCS5Padding";	// mode ECB/CBC/OFB/CFB/CTR
    	private static String aes_mode_cbc_pkcs5 = "AES/CBC/PKCS5Padding";
    	//private static String aes_mode_cfb_pkcs5 = "AES/CFB/PKCS5Padding";	// java jdk is not surport
    	//private static String aes_mode_ofb_pkcs5 = "AES/OFB/PKCS5Padding";	// java jdk is not surport
    	//private static String aes_mode_ctr_pkcs5 = "AES/CTR/PKCS5Padding";	// java jdk is not surport
    	
    	private static String aes_algorithm = "AES";
    	
    	private static String aes_key_padding_str = "1234567890ABCDEF";
    	private static String aes_iv_padding_str = "ABCDEFGH12345678";
    	
    	private static byte[] default_iv = { 0x12, 0x34, 0x56, 0x78, 
    		(byte) Integer.parseInt("90", 16),
    		(byte) Integer.parseInt("AB", 16),
    		(byte) Integer.parseInt("CD", 16),
    		(byte) Integer.parseInt("EF", 16),
    		 								 0x12, 0x34, 0x56, 0x78, 
    		(byte) Integer.parseInt("90", 16),
    		(byte) Integer.parseInt("AB", 16),
    		(byte) Integer.parseInt("CD", 16),
    		(byte) Integer.parseInt("EF", 16)};
    	
    	private static byte[] key_generator(String p_key){
    		byte[] key = (p_key +aes_key_padding_str).substring(0, 16).getBytes();
    		return key;
    	}
    	private static byte[] iv_generator(String p_iv){
    		byte[] iv = (p_iv + aes_iv_padding_str).substring(0,16).getBytes();
    		return iv;
    	}
    	
    	public static byte[] ecb_aes_encrypt(byte[] s_buf,byte[] p_pass){
    		return ecb_base_encrypt(aes_mode_ecb_pkcs5, aes_algorithm,s_buf, p_pass);
    	}
    	public static byte[] ecb_aes_decrypt(byte[] s_buf,byte[] p_pass){
    		return ecb_base_decrypt(aes_mode_ecb_pkcs5, aes_algorithm, s_buf, p_pass);
    	}
    	public static byte[] ecb_aes_encrypt(byte[] s_buf,String p_pass) {
    		byte[] p_key = key_generator(p_pass);
    		return ecb_base_encrypt(aes_mode_ecb_pkcs5, aes_algorithm, s_buf, p_key);
    	}
    	public static byte[] ecb_aes_decrypt(byte[] s_buf,String p_pass){
    		
    		byte[] p_key = key_generator(p_pass);
    		return ecb_base_decrypt(aes_mode_ecb_pkcs5, aes_algorithm, s_buf, p_key);
    	}
    	
    	
    	public static byte[] aes_cbc_encrypt(byte[] s_buf,byte[] p_pass,byte[] p_iv){
    		return base_encrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_pass, p_iv);
    	}
    	public static byte[] aes_cbc_decrypt(byte[] s_buf,byte[] p_pass,byte[] p_iv) {
    		return base_decrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_pass, p_iv);
    	}
    	public static byte[] aes_cbc_encrypt(byte[] s_buf,byte[] p_pass){
    		return base_encrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_pass, default_iv);
    	}
    	public static byte[] aes_cbc_decrypt(byte[] s_buf,byte[] p_pass){
    		return base_decrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_pass, default_iv);
    	}
    	public static byte[] aes_cbc_encrypt(byte[] s_buf,String p_pass,String p_iv){
    		byte[] key = key_generator(p_pass);
    		byte[] iv = iv_generator(p_iv);
    		return base_encrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, key, iv);
    	}
    	public static byte[] aes_cbc_decrypt(byte[] s_buf,String p_pass,String p_iv){
    		byte[] key = key_generator(p_pass);
    		byte[] iv = iv_generator(p_iv);
    		return base_decrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, key, iv);
    	}
    	public static byte[] aes_cbc_encrypt(byte[] s_buf,String p_pass){
    		byte[] p_key = key_generator(p_pass);
    		return base_encrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_key,default_iv);
    	}
    	public static byte[] aes_cbc_decrypt(byte[] s_buf,String p_pass){
    		byte[] p_key = key_generator(p_pass);
    		return base_decrypt(aes_mode_cbc_pkcs5, aes_algorithm, s_buf, p_key,default_iv);
    	}
    
    }
    


    展开全文
  • AES java 与 C#加密解密

    2015-01-08 11:35:52
    java c# 加密解密
  • aes java源码这很棒- // // IntelliJ IDEA从.class文件重新创建的源代码//(由Fernflower反编译器提供支持)//程序包sun.security.pkcs11; 导入java.io.File; 导入java.io.IOException; 导入java.io.InputStream; ...
  • AES Java加密 C#解密 (128-ECB加密模式)

    千次阅读 2017-07-03 15:00:20
    在项目中遇到这么一个问题:java端需要把一些数据AES加密后传给C#端,找了好多资料,算是解决了,分享一下:import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder;import javax.crypto.Cipher; import ...

    在项目中遇到这么一个问题:

    java端需要把一些数据AES加密后传给C#端,找了好多资料,算是解决了,分享一下:

    import sun.misc.BASE64Decoder;
    import sun.misc.BASE64Encoder;
    
    import javax.crypto.Cipher;
    import javax.crypto.KeyGenerator;
    import java.security.SecureRandom;
    
    public class AesEncodeUtil {
    
      private final static String transferKey ="qazwsxedcrfv12345";
    
      public static void main(String[] args) throws Exception {
    
    
        String a = aesTransferEncrypt("QAZwsx123!@#$%^&*");
        System.out.println(a);
        System.out.println(aesTransferDncrypt(a));
    
      }
    
      /**
       * 传输用加密
       * @param content
       * @return
       * @throws Exception
       */
      public static String aesTransferEncrypt(String content) throws Exception {
        return base64Encode(aesEncryptToBytes(content, transferKey));
      }
    
      /**
       * 传输用解密
       * @param content
       * @return
       * @throws Exception
       */
      public static String aesTransferDncrypt(String encryptStr) throws Exception {
        return aesDecryptByBytes(base64Decode(encryptStr), transferKey);
      }
    
      /**
       * base 64 encode
       * @param bytes 待编码的byte[]
       * @return 编码后的base 64 code
       */
      private static String base64Encode(byte[] bytes) {
        return new BASE64Encoder().encode(bytes);
      }
    
      /**
       * base 64 decode
       * @param base64Code 待解码的base 64 code
       * @return 解码后的byte[]
       * @throws Exception
       */
      private static byte[] base64Decode(String base64Code) throws Exception {
        return new BASE64Decoder().decodeBuffer(base64Code);
      }
    
      /**
       * AES加密
       * @param content 待加密的内容
       * @param encryptKey 加密密钥
       * @return 加密后的byte[]
       * @throws Exception
       */
      private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG" );
        secureRandom.setSeed(encryptKey.getBytes());
        kgen.init(128, secureRandom);
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, kgen.generateKey());
        return cipher.doFinal(content.getBytes("UTF-8"));
      }
    
      /**
       * AES解密
       * @param encryptBytes 待解密的byte[]
       * @param decryptKey 解密密钥
       * @return 解密后的String
       * @throws Exception
       */
      private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
        KeyGenerator kgen = KeyGenerator.getInstance("AES");
        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG" );
        secureRandom.setSeed(decryptKey.getBytes());
        kgen.init(128, secureRandom);
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE,kgen.generateKey());
        byte[] decryptBytes = cipher.doFinal(encryptBytes);
        return new String(decryptBytes,"UTF-8");
      }
    }

    java代码加密/解密运行结果:

    加密结果:BKscOr7eK4jTO5Hcw5oxqS8HWg2SRhtGfMctz8t/45g=
    解密结果:QAZwsx123!@#$%^&*

    再看看C#代码:

    /// <summary>
            /// AES加密 (128-ECB加密模式)
            /// </summary>
            /// <param name="toEncrypt">内容</param>
            /// <param name="key">秘钥</param>
            /// <returns></returns>
            public static string AESEncrypt(string toEncrypt, string key)
            {
                byte[] keyArray = Convert.FromBase64String(key);
                byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt);
    
                RijndaelManaged rDel = new RijndaelManaged();
                rDel.Key = keyArray;
                rDel.Mode = CipherMode.ECB;
                rDel.Padding = PaddingMode.PKCS7;
    
                ICryptoTransform cTransform = rDel.CreateEncryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
    
                return Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            /// <summary>
            /// AES解密(128-ECB加密模式)
            /// </summary>
            /// <param name="toDecrypt">密文</param>
            /// <param name="key">秘钥(Base64String)</param>
            /// <returns></returns>
            public static string AESDecrypt(string toDecrypt, string key)
            {
                try
                {
                    byte[] keyArray = Convert.FromBase64String(key); //128bit
                    byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);
                    RijndaelManaged rDel = new RijndaelManaged();
                    rDel.Key = keyArray; //获取或设置对称算法的密钥
                    rDel.Mode = CipherMode.ECB; //获取或设置对称算法的运算模式,必须设置为ECB  
                    rDel.Padding = PaddingMode.PKCS7; //获取或设置对称算法中使用的填充模式,必须设置为PKCS7  
                    ICryptoTransform cTransform = rDel.CreateDecryptor(); //用当前的 Key 属性和初始化向量 (IV) 创建对称解密器对象
                    byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                    return Encoding.UTF8.GetString(resultArray);
                }
                catch
                {
                    return null;
                }
            }

    但是如果直接把 transferKey =”qazwsxedcrfv12345” 和 加密结果:BKscOr7eK4jTO5Hcw5oxqS8HWg2SRhtGfMctz8t/45g=

    给C#,C#是无法解密的,因为 rDel.Key = keyArray; 会报错。

    那么怎么办呢? 其实我们要把transferKey =”qazwsxedcrfv12345” 处理下,

    import java.security.NoSuchAlgorithmException;
    import javax.crypto.KeyGenerator;
    import javax.crypto.SecretKey;
    import sun.misc.BASE64Encoder;
    
    public class t1 {
    
    public static void main(String[] args) throws NoSuchAlgorithmException {
    String transferKey ="btnm018idnwtyaTNNkkdTnd11_!@$TTASdg212c21_djTdj";
    KeyGenerator kgen = KeyGenerator.getInstance("AES");
    java.security.SecureRandom random = java.security.SecureRandom.getInstance("SHA1PRNG");
    random.setSeed(transferKey.getBytes());
    kgen.init(128, random);
    SecretKey secretKey = kgen.generateKey();
    byte[] enCodeFormat = secretKey.getEncoded();
    BASE64Encoder coder = new BASE64Encoder();
    
    System.out.println(coder.encode(enCodeFormat));
    
    }
    
    }

    运行结果:0UkIZmHsXb0BUql/L3R6Aw== 才是C#需要的key

    看看C#调用及结果:
    这里写图片描述
    以上只是一个简单的示例。

    展开全文
  • Java AES加密Java AES加密Java AES加密Java AES加密Java AES加密Java AES加密Java AES加密
  • AES in Java

    2009-09-01 23:00:22
    Rijndael算法的AES Java代码
  • java Aes.java

    2021-02-24 11:13:18
    java AES加密传输
  • java_AES javaAES的md5后的base64加解密
  • AES for JAVA

    2011-10-19 16:30:20
    AES for JAVA Source Code
  • AES_Java 使用Java实现AES加密算法的完整过程
  • java代码-java aes

    2021-07-16 13:23:44
    java代码-java aes

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 34,613
精华内容 13,845
关键字:

aesjava

java 订阅