aes

Java 加密 AES 对称加密算法

ε祈祈猫儿з 提交于 2020-01-04 03:36:47
版权声明:本文为博主原创文章,未经博主允许不得转载。 【AES】 一种对称加密算法,DES的取代者。 加密相关文章见: Java 加密解密 对称加密算法 非对称加密算法 MD5 BASE64 AES RSA 【代码】 代码比较多,有一部分非本文章内容代码,具体自己看吧。 [java] view plain copy package com.uikoo9.util.encrypt; import java.math.BigInteger; import java.security.MessageDigest; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import com.uikoo9.util.QStringUtil; /** * 编码工具类 * 1.将byte[]转为各种进制的字符串 * 2.base 64 encode * 3.base 64 decode * 4.获取byte[]的md5值 * 5.获取字符串md5值 * 6

AES加密工具类(对称加密算法)

限于喜欢 提交于 2020-01-04 03:36:34
import java.nio.charset.Charset; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import com.jfinal.log.Log; /** * AES安全编码组件 * * 高级数据加密标准---AES:由于DES的问题所以产生了AES,像是DES的升级,密钥建立时间短,灵敏性好,内存要求低,被广泛应用 * * 说明: * * 对于java.security.InvalidKeyException: Illegal key size or default * parameters异常, 去掉这种限制需要下载Java Cryptography Extension (JCE) Unlimited Strength * Jurisdiction Policy Files, 下载包的readme.txt * 有安装说明。就是替换${java_home}/jre/lib/security/ * 下面的local_policy.jar和US_export_policy.jar */ public

PHP进行AES/ECB/PKCS7 padding加密的例子(mcrypt)

时光总嘲笑我的痴心妄想 提交于 2020-01-04 03:33:50
业务需要,需要对数据进行加密( AES/ECB/PKCS7Padding ),由于之前对该内容了解较少,于是去网上搜寻答案,很庆幸,很快搜索到一个例子,基本不用改动什么就可以使用,但是里面有不少内容还不是很了解,现在把它记下来日后慢慢学习。 <?php class AES { protected $cipher; protected $mode; protected $pad_method; protected $secret_key; protected $iv; public function __construct($key, $method = 'pkcs7', $iv = '', $mode = MCRYPT_MODE_ECB, $cipher = MCRYPT_RIJNDAEL_128) { $this->secret_key = $key; $this->pad_method =$method; $this->iv = $iv; $this->mode = $mode; $this->cipher = $cipher; } protected function pad_or_unpad($str, $ext) { if (!is_null($this->pad_method)) { $func_name = __CLASS__ . '::' . $this->pad

c# Aes加解密

爷,独闯天下 提交于 2020-01-04 03:29:00
using System; using System.Collections.Generic; using System.IO; using System.Security.Cryptography; using System.Text; namespace ConsoleApp1 { internal class Program { /// <summary> /// /// </summary> /// <param name="args"></param> private static void Main(string[] args) { string IVString = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";//IV string key = "IE7XG5ORF7EA4JC5";//key string encrypt = "3duwmKQ5ED4FRz3UtSN2zMvrLOPEiGn9Fwj2oEJngww="; string decrypt = "3001004"; //加密 string encryptValue = AesEncrypt(decrypt, key, IVString); Console.WriteLine(encryptValue); Console.WriteLine(encryptValue.Equals

AES OFB encryption for RijndaelManaged

纵然是瞬间 提交于 2020-01-03 17:28:36
问题 I need to communicate from a C# application to another application via encrypted messages in OFB mode. I know that RijndaelManaged does not have support for AES OFB mode. Is there anybody more experienced than me aware of any other way to encrypt/decrypt using OFB mode? 回答1: The following stream implements OFB by using a key stream generated by a zero-fed CBC cipher stream. public class OFBStream : Stream { private const int BLOCKS = 16; private const int EOS = 0; // the goddess of dawn is

How to AES CBC encryption Using cryptoAPI

爱⌒轻易说出口 提交于 2020-01-03 06:06:37
问题 I want to encrypt a file with AES CBC mode encryption, Using cryptoAPI functions and set my own key from the command-line (It my change in the code) I imagine that the key (after change) will be 1a1dc91c907325c6 and tried in this form: HCRYPTPROV hProv = NULL; HCRYPTKEY hKey = NULL; DWORD dwBlobLen; PBYTE pbKeyBlob = NULL; pbKeyBlob = (PBYTE)"1a1dc91c907325c6"; if(!CryptAcquireContext(&hProv, NULL,NULL, PROV_RSA_AES,CRYPT_VERIFYCONTEXT)) { printf(" Error in AcquireContext 0x%08x \n"

vue中使用aes加密

ε祈祈猫儿з 提交于 2020-01-03 05:05:01
1、安装 npm install crypto-js 2、创建aes.js文件 我是放在src/utils/aes.js 3、aes页面引入方法 import CryptoJS from 'crypto-js/crypto-js' /* * 默认的 KEY IV 如果在加密解密的时候没有传入KEY和IV,就会使用这里定义的 * * 前后端交互时需要前后端密钥和初始向量保持一致 */ const KEY = CryptoJS.enc.Utf8.parse("1234567890ABCDEF");// 密钥 长度必须为16位 const IV = CryptoJS.enc.Utf8.parse("123456"); // 初始向量 长度随意 /* * AES加密 :字符串 key iv 返回base64 */ export function encrypt(str, keyStr, ivStr) { let key = KEY let iv = IV if (keyStr && ivStr) { key = CryptoJS.enc.Utf8.parse(keyStr); iv = CryptoJS.enc.Utf8.parse(ivStr); } let srcs = CryptoJS.enc.Utf8.parse(str); var encrypt = CryptoJS.AES

Java TLS 1.2 server : AES-GCM decryption

心已入冬 提交于 2020-01-03 04:53:04
问题 I'm currently working on a Java TLS server. (I posted here a few days ago regarding KeyExchange signature) I'm now trying to decrypt TLS message encoded using AES-GCM. The server already handles CBC but since it's vulnerable to POODLE we'd like to do GCM instead. I'll try to explain as best as I can :) For this code we are using Java 8u91, Netty 3.9.0. We do not use BouncyCastle and we don't intend to, we would like to stick with the JDK. The code ! /** * Deciphers the fragment and returns

AES decrypt fails with “Padding is invalid and cannot be removed”

末鹿安然 提交于 2020-01-03 03:10:07
问题 I am making cross-platform application with server being written in Java, so I ended up with C# for Windows. I finally got through all obstacles like different endianities for BigIntegers in these two languages (Java: big endian, C#: little), so I successfuly made key-exchange as well. Now this is where problem comes, in Java I use AES/CBC/PKCS5Padding for encryption, but in C# there was no PKCS5 available, but as I read in other posts to this topic here on SO, PKCS7 is told to be same as

WP: AesManaged encryption vs. mcrypt_encrypt

橙三吉。 提交于 2020-01-02 17:41:06
问题 I'm trying to synchronize my encryption and decryption methods between C# and PHP but something seems to be going wrong. In the Windows Phone 7 SDK you can use AESManaged to encrypt your data I use the following method: public static string EncryptA(string dataToEncrypt, string password, string salt) { AesManaged aes = null; MemoryStream memoryStream = null; CryptoStream cryptoStream = null; try { //Generate a Key based on a Password, Salt and HMACSHA1 pseudo-random number generator