aes

Parallel simulation of AES in C using Openmp

末鹿安然 提交于 2020-01-23 16:21:12
问题 Here is my problem. I want to parallelize AES-128 encryption in C using Openmp. I am hardly getting any speedup with the following code using openmp. My machine is Quadcore intel i5 machine. Here is the code. Any suggestion how to parallelize this code further would be really really appreciated. Please take a look at the main function which is at the end of the code. AES code below consists of a few functions to achieve its functionality. Please suggest how to best extract parallelism from

AES加密工具

て烟熏妆下的殇ゞ 提交于 2020-01-23 13:01:46
public class AES { /** * 加密 * * @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

Python加密AES

我的未来我决定 提交于 2020-01-23 05:25:30
安装 pycrypto、pycrytodome和crypto是一个东西,crypto在python上面的名字是pycrypto,它是一个第三方库,但是已经停止更新三年了,所以不建议安装这个库; 这个时候pycryptodome就来了,它是pycrypto的延伸版本,用法和pycrypto是一模一样的; 所以,我现在告诉大家一种解决方法–直接安装:pip install pycryptodome 但是,在使用的时候导入模块是有问题的,这个时候只要修改一个文件夹的名称就可以完美解决这个问题, 将文件夹叫做crypto,将小写c改成大写C就ok了。 参考: windows下安装crypto from Crypto . Cipher import AES from binascii import b2a_hex , a2b_hex class BaseCrypt ( object ) : def __init__ ( self , * args , key = None , ** kwargs ) : self . key = key def encrypt ( self , text ) : raise NotImplementedError def decrypt ( self , text ) : raise NotImplementedError class AESCrypt (

Decrypting “SunJCE” AES encrypted data on Android

て烟熏妆下的殇ゞ 提交于 2020-01-22 13:11:30
问题 We need to write some Android code to decrypt some data sent from our server. Our server team gave us some sample decryption code which uses the "SunJCE" provider, which unfortunately doesn't exist on Android. Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); Does anybody know the cleanest way to implement this on Android? If we try this on Android Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); then it looks like some unwanted garbage appears at the end of the

AES加密

人走茶凉 提交于 2020-01-22 01:53:08
常见的加密方法有MD5、RSA、AES,今天我们来说说AES加密,没啥好说的,直接给大家上demo。 1 package com.ecshop.common.util; 2 3 4 import sun.misc.BASE64Decoder; 5 import sun.misc.BASE64Encoder; 6 7 import javax.crypto.Cipher; 8 import javax.crypto.spec.IvParameterSpec; 9 import javax.crypto.spec.SecretKeySpec; 10 11 12 public class AESUtil { 13 //算法 14 private static final String ALGORITHM = "AES"; 15 //默认的加密算法 16 private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; 17 // 编码 18 private static final String ENCODING = "UTF-8"; 19 // 密匙 20 private static final String KEY = "a70648d869329dab"; 21 // 偏移量 22 private

C#对接JAVA系统遇到的AES加密坑

两盒软妹~` 提交于 2020-01-21 22:40:07
起因对接合作伙伴的系统,需要对数据进行AES加密 默认的使用了已经写好的帮助类中加密算法,发现结果不对,各种尝试改变加密模式改变向量等等折腾快一下午。最后网上查了下AES在JAVA里面的实现完整代码如下: public static String AesEncrypt(String content,String encyKey) { try { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); secureRandom.setSeed(encyKey.getBytes()); kgen.init(128, secureRandom); Cipher cipher=Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(kgen.generateKey().getEncoded(),"AES")); byte[] byteContent = content.getBytes("utf-8"); byte[] result = cipher.doFinal(byteContent);

AES加密(java和C#)

孤街浪徒 提交于 2020-01-21 22:26:45
需求:Java和C#进行数据交互,互相采用AES/CBC/PKCS5Padding进行加解密 Java加密和解密的代码如下: /** * 加密 1.构造密钥生成器 2.根据 ecnodeRules 规则初始化密钥生成器 3.产生密钥 4.创建和初始化密码器 5.内容加密 6.返回字符串 * @param encodeRules 密钥规则,类似于密钥 * @param content 待加密内容 * @return */ public static String AESEncode(String encodeRules, String content) { // 初始化向量,必须 16 位 String ivStr = "AESCBCPKCS5Paddi"; try { // 1.构造密钥生成器,指定为 AES 算法,不区分大小写 KeyGenerator keygen = KeyGenerator.getInstance("AES"); // 新增下面两行,处理 Linux 操作系统下随机数生成不一致的问题 SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); secureRandom.setSeed(encodeRules.getBytes()); keygen.init(128,

AES 对称加解密

时光怂恿深爱的人放手 提交于 2020-01-20 00:14:30
1.生成AES Key /** * AES根据密码生成Key * @param password * @return */ public static Key createKey(String password) { // 构造密码生成器,指定为AES算法 try { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); // 生成128位的随机源 keyGenerator.init(128, new SecureRandom(password.getBytes())); // 产生原始对称秘钥 SecretKey secretKey = keyGenerator.generateKey(); // 获得原始对称秘钥的字节数组 byte[] encodedBytes = secretKey.getEncoded(); // Key转换,根据字节数组生成AES秘钥 return new SecretKeySpec(encodedBytes, "AES"); } catch (Exception e) { LOG.error("generate key fail"); } return null; } 2.AES加密(ECB模式) /** * AES加密操作,使用ECB模式 * @param contents *

vue中使用AES加密

寵の児 提交于 2020-01-18 09:47:05
vue中使用AES加密 先安装 npm install crypto-js --save-dev 在项目中新建一个utils.js文件 我建在 src/assets/js/utils.js utils.js文件中的内容 import CryptoJS from 'crypto-js/crypto-js' // 默认的 KEY 与 iv 如果没有给 const KEY = CryptoJS.enc.Utf8.parse("123");//""中与后台一样 密码 const IV = CryptoJS.enc.Utf8.parse();//""中与后台一样 /** * AES加密 :字符串 key iv 返回base64 */ export function Encrypt(word, keyStr, ivStr) { let key = KEY let iv = IV if (keyStr) { key = CryptoJS.enc.Utf8.parse(keyStr); iv = CryptoJS.enc.Utf8.parse(ivStr); } let srcs = CryptoJS.enc.Utf8.parse(word); var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode

AES CBC模式下的Padding Oracle解密

别来无恙 提交于 2020-01-18 04:24:33
AES CBC模式下的Padding Oracle解密 /*--> */ /*--> */ */ /*--> */ */ /*--> */ */ /*--> */ */ /*--> */ AES CBC模式下的Padding Oracle解密 目录 1. 简介 2. aes cbc加解密测试程序 3. Padding Oracle Attack过程 4. 总结 1 简介 Padding Oracle攻击方法出现的也比较早了,参考 padding oracle attack ,这篇文章写的比较好。 也可以参考 ctf-wiki 。 Padding Oracle Attack主要是针对CBC分组加密的情况,通过padding来测试每个分组的每个字节是否正确来获取分组的中间状态值,上一个分组XOR中间状态值就是明文。第一个分组使用初始IV来XOR获得明文。 图1 CBC模式一个分组的解密过程 2 aes cbc加解密测试程序 用FLASK实现一个aes cbc加解密的测试程序,代码如下,保存为aes_server.py: #!/usr/bin/python # coding=utf-8 # python 3 # 安装依赖 pip3 install PyCrypto flask # 运行 FLASK_APP=aes_server.py flask run from http.server