aes

python 实现 AES CBC模式加解密

元气小坏坏 提交于 2019-11-28 19:16:20
AES加密方式有五种:ECB, CBC, CTR, CFB, OFB 从安全性角度推荐CBC加密方法,本文介绍了CBC,ECB两种加密方法的python实现 python 在 Windows 下使用AES时要安装的是pycryptodome 模块 pip install pycryptodome python 在 Linux 下使用AES时要安装的是pycrypto模块 pip install pycrypto CBC加密需要一个十六位的key(密钥)和一个十六位iv(偏移量) 1. 加密 加密时,明文首先与IV异或,然后将结果进行块加密,得到的输出就是密文,同时本次的输出密文作为下一个块加密的IV。 2. 解密 解密时,先将密文的第一个块进行块解密,然后将结果与IV异或,就能得到明文,同时,本次解密的输入密文作为下一个块解密的IV。 3. 代码:    # -*- coding=utf-8-*- from Crypto.Cipher import AES import os from Crypto import Random import base64 """ aes加密算法 padding : PKCS7 """ class AESUtil: __BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size @staticmethod def

python 实现 AES ECB模式加解密

拈花ヽ惹草 提交于 2019-11-28 19:15:50
AES ECB模式加解密 使用cryptopp完成AES的ECB模式进行加解密。 AES加密数据块分组长度必须为128比特,密钥长度可以是128比特、192比特、256比特中的任意一个。(8比特 == 1字节) 在CBC、CFB、OFB、CTR模式下除了密钥外,还需要一个初始化向IV。(ECB模式不用IV) 代码:    # -*- coding=utf-8-*- from Crypto.Cipher import AES import os from Crypto import Random import base64 """ aes加密算法 padding : PKCS7 """ class AESUtil: __BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size @staticmethod def encryt(str, key, iv): cipher = AES.new(key, AES.MODE_ECB,iv) x = AESUtil.__BLOCK_SIZE_16 - (len(str) % AESUtil.__BLOCK_SIZE_16) if x != 0: str = str + chr(x)*x msg = cipher.encrypt(str) # msg = base64.urlsafe_b64encode(msg

AES256 NSString Encryption in iOS

依然范特西╮ 提交于 2019-11-28 18:53:54
My app encrypts and decrypts (or it should) an NSString (the text to be encrypted / decrypted) with another NSString (the keyword) using aes 256-Bit Encryption. When I run my project and run the encrypt method, nothing gets encrypted the textfield just clears itself. Here is the code I have: -(void)EncryptText { //Declare Keyword and Text NSString *plainText = DataBox.text; NSString *keyword = Keyword.text; //Convert NSString to NSData NSData *plainData = [plainText dataUsingEncoding:NSUTF8StringEncoding]; //Encrypt the Data NSData *encryptedData = [plainData AESEncryptWithPassphrase:keyword];

Encrypting and Decrypting with python and nodejs

时光毁灭记忆、已成空白 提交于 2019-11-28 18:26:43
I'm trying to encrypt some content in Python and decrypt it in a nodejs application. I'm struggling to get the two AES implementations to work together though. Here is where I am at. In node: var crypto = require('crypto'); var password = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; var input = 'hello world'; var encrypt = function (input, password, callback) { var m = crypto.createHash('md5'); m.update(password) var key = m.digest('hex'); m = crypto.createHash('md5'); m.update(password + key) var iv = m.digest('hex'); // add padding while (input.length % 16 !== 0) { input += ' '; } var data = new

256bit AES/CBC/PKCS5Padding with Bouncy Castle

二次信任 提交于 2019-11-28 18:26:12
I am having trouble mapping the following JDK JCE encryption code to Bouncy Castles Light-weight API: public String dec(String password, String salt, String encString) throws Throwable { // AES algorithm with CBC cipher and PKCS5 padding Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); // Construct AES key from salt and 50 iterations PBEKeySpec pbeEKeySpec = new PBEKeySpec(password.toCharArray(), toByte(salt), 50, 256); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithSHA256And256BitAES-CBC-BC"); SecretKeySpec secretKey = new SecretKeySpec(keyFactory

AES encryption how to transport IV

╄→尐↘猪︶ㄣ 提交于 2019-11-28 18:16:05
I understand that unique IV is important in encrypting to prevent attacks like frequency analysis. The question: For AES CBC encryption, whats the importance of the IV? has a pretty clear answer explaining the importance of the IV. Would there be any security holes in sending the IV in clear text? Or would it need to be encrypted with the same public/private key that was used to send the symmetric key? If the IV needs to be sent encrypted, then why not generate a new symmetric key each time and consider the IV as part of the key? Is it that generating a symmetric key is too costly? Or is it to

SQL Server 2008 Open Master Key error upon physical server change over

て烟熏妆下的殇ゞ 提交于 2019-11-28 17:11:49
问题 I copied a SQL Server database from one system to the next, identical setup, but completely different physical machine. I used Norton Ghost and recoverd files manually, for example, the entire SQL Server 2008 folder found in c:\Program Files after re-installing SQL Server 2008 Express. One of my databases has AES_256 encryption enabled on a number of one of its tables, columns. I resetup my IIS7 and tried to run the app that access the database, upon retrieving the data, I get this error:

How to fix Invalid AES key length?

ε祈祈猫儿з 提交于 2019-11-28 17:02:47
I am working on a text encryption and decryption project (following Struts 2) Whenever I enter the password and the plain text I get a Invalid AES Key Length error. The Service Class package com.anoncrypt.services; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class SymAES { private static final String ALGORITHM = "AES"; private static byte[] keyValue= new byte[] { 'T', 'h', 'i', 's', 'I', 's', 'A', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y' }; public String encode(String

When compressing and encrypting, should I compress first, or encrypt first?

与世无争的帅哥 提交于 2019-11-28 16:29:20
If I were to AES-encrypt a file, and then ZLIB-compress it, would the compression be less efficient than if I first compressed and then encrypted? In other words, should I compress first or encrypt first, or does it matter? Compress first. Once you encrypt the file you will generate a stream of random data, which will be not be compressible. The compression process depends on finding compressible patterns in the data. maxbublis Compression before encryption is surely more space efficient but in the same time less secure. That's why I would disagree with other answers. Most compression

Java实现AES加密解密

时光怂恿深爱的人放手 提交于 2019-11-28 16:24:46
之前常用两种加密算法:Base64和Md5,前者容易破解,后者不可逆。 AES采用对称加密方式,破解难度非常大,在可逆的基础上,能很好的保证数据的安全性。 这里介绍Java中实现AES加密算法的加密与解密实现: import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import org.springframework.util.Base64Utils; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; import java.security.Key; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; public class AesUtil { public static void main(String[] args) throws