aes

Why is this string not equal when it is decrypted a second time with AesCryptoServiceProvider?

天涯浪子 提交于 2020-01-13 17:07:14
问题 I'm having trouble with encryption and decryption of text in C# (VS2012, .NET 4.5). Specifically, When I encrypt and subsequently decrypt a string, the output is not the same as the input. However, bizarrely, if I copy the encrypted output and hardcode it as a string literal, decryption works. The following code sample illustrates the problem. What am I doing wrong? var key = new Rfc2898DeriveBytes("test password", Encoding.Unicode.GetBytes("test salt")); var provider = new

AES中ECB模式的加密与解密(Python3.7)

痞子三分冷 提交于 2020-01-13 14:04:32
本文主要解决的问题 本文主要是讲解AES加密算法中的ECB模式的加密解密的Python3.7实现。具体AES加密算法的原理这里不做过多介绍,想了解的可以参考文末的参考链接。 主要解决了两个问题: 在Python3.7版本下,所依赖包的安装问题 。(有一些博客时间久远,其中所提到的模块并不适用于Python3.7) 因为Python版本的问题,其他博客在基于Python3.6下的代码在Python3.7下并不能运行的问题 。 背景介绍 在爬虫项目中遇到,某些网站的账号、密码采用了AES的ECB模式进行了加密。 # 加密前的数据 123456asd # 加密后的数据 3cfeba82c31b6635e8fb085e04529e74 # 密钥 8NONwyJtHesysWpM 使用 在线AES加密解密、AES在线加密解密 ,进行尝试。 经过测试发现,在 AES 加密的 ECB模式 ,填充为 pkcs7padding ,数据块为 128位 ,输出格式为 hex 时,得到自己想要的结果。 (这里可以可以根据密文的格式进行判断输出的格式, 一般密文以==结尾的输出格式为base64 ,否则为hex格式) 问题1:Crypto模块安装报错 pip 安装 pycrypto模块,抛如下错误: error: command 'C:\\Program Files (x86)\\Microsoft

http和https ,https申请ssl证书

我与影子孤独终老i 提交于 2020-01-13 11:57:53
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="200" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLSv1.2" keystoreFile="D:/tomcat/apache-tomcat-7.0.78-SSL/conf/jks/ssl.jks" keystorePass="这个是申请时候填写的密码" URIEncoding="UTF-8" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" ciphers="TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES

What does cipher.update do in java?

一个人想着一个人 提交于 2020-01-13 06:42:48
问题 I am implementing DES - CBC. I am confused as to what cipher.init , cipher.update and cipher.dofinal do. I just use init to set the key and dofinal to get the result. I don't use update. Is that correct? Also whats the difference to the result when using UTF-8 and ASCII encodings? Here is my code: byte[] ciphertext; Cipher enc = Cipher.getInstance("DES/CBC/PKCS5Padding"); enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "DES"), new IvParameterSpec(vector)); // Is this the complete

perl CBC DES equivalent in java

淺唱寂寞╮ 提交于 2020-01-13 06:36:10
问题 We are migrating some code from perl to java/scala and we hit a roadblock. We're trying to figure out how to do this in Java/scala: use Crypt::CBC; $aesKey = "some key" $cipher = new Crypt::CBC($aesKey, "DES"); $encrypted = $cipher->encrypt("hello world"); print $encrypted // prints: Salted__�,%�8XL�/1�&�n;����쀍c $decrypted = $cipher->decrypt($encrypted); print $decrypted // prints: hello world I tried a few things in scala but didn't really get it right, for example something like this: val

Bouncy Castle's Password Based Encryption With AES in CBC mode

谁说胖子不能爱 提交于 2020-01-13 05:51:06
问题 I've recently came across a piece of code that uses BouncyCastle's PBE with AES in CBC mode ("PBEWithSHA1And256BitAES-CBC-BC"). public static final String ALGORITHM = "PBEWithSHA1And256BitAES-CBC-BC"; public static byte[] encrypt(final byte[] key, final byte[] salt, final byte[] plainText) throws CryptoException { try { // Create the encryption key final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM, "BC"); final PBEKeySpec keySpec = new PBEKeySpec(new String(key)

Decrypting file in C++, which was encrypted with openssl -aes-128-cbc

☆樱花仙子☆ 提交于 2020-01-13 05:38:28
问题 I'm trying to decrypt a file in C++. This file is encrypted with the following command: openssl enc -nosalt -aes-128-cbc -pass pass:test -in "test.txt" -out "test_enc.txt" -p The console shows the key=098F6BCD4621D373CADE4E832627B4F6 and iv=0A9172716AE6428409885B8B829CCB05 . In C++ I have included the #include openssl/aes.h line and try to decrypt with the following code: const char *indata = string.toAscii().constData(); unsigned char outdata[strlen(indata)]; unsigned char ckey[] =

Python3 AES加解密(AES/ECB/PKCS5Padding)

Deadly 提交于 2020-01-13 05:16:02
class AesEncry(object): key = "wwwwwwwwwwwwwwww" # aes秘钥 def encrypt(self, data): data = json.dumps(data) mode = AES.MODE_ECB padding = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16) cryptos = AES.new(self.key, mode) cipher_text = cryptos.encrypt(padding(data).encode("utf-8")) return base64.b64encode(cipher_text).decode("utf-8") def decrypt(self, data): cryptos = AES.new(self.key, AES.MODE_ECB) decrpytBytes = base64.b64decode(data) meg = cryptos.decrypt(decrpytBytes).decode('utf-8') return meg[:-ord(meg[-1])]    来源: https://www.cnblogs.com/wxp5257/p/11468538.html

java.security AES encryption key length

折月煮酒 提交于 2020-01-13 05:07:25
问题 When the key length is 128 bits,everything works. But I got the following exception when I use a key of length 192 or 256 bits. java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) I found this Java Security: Illegal key size or default parameters?. But after I download the jar

Making AES decryption fail if invalid password

别等时光非礼了梦想. 提交于 2020-01-13 03:13:07
问题 I've written my own encryption method using AES in a project I've been working on lately using PyCrypto. I use a hash to generate a 32-byte password and feed that to AES-256bit encryption using CBC. The file input is padding using PKCS#7 padding to conform to be divisible by 16. I can encrypt and decrypt the file without incident and the input file originally encrypted along with the output file have the same SHA-256 hash. The only problem I'm finding is that if I supply the wrong passphrase,