aes

How to deserialize byte[] into generic object to be cast at method call

你。 提交于 2019-12-04 05:56:51
I am working on an object encryption class. I have everything worked out but I want to be able to encrypt/decrypt any object type with one deserialize method. As of now the only thing holding me up is the deserialize method. I have the function returning type(object) in the hopes of returning a weak typed object. It works as long as I cast the type during the return value assignment, but If I deserialize into type 'object' the result is byte[]. This means that I have to write a deserialize method for every object(T) i want to operate on. What I want to do is pass Type(T) as a parameter to the

php7 openssl_decrypt AES的ECB与CBC加解密

蹲街弑〆低调 提交于 2019-12-04 05:49:54
php7.2版本用openssl_encrypt代替mcrypt_encrypt,导致以往自己写的Aes加密类不能用。 这次项目客户端用的是 AES-128-ECB 加密,我用在线AES工具来测试,发现自己写的加解密方法得到的值不一样。而最终发现是加密的key不是16位长,导致ios客户端与服务器php的加解密不一致。后商讨key为16位长,遂问题解决。下面是 AES-128-ECB 加密类; class Aes { //密钥 须是16位 public $key ; /** * 解密字符串 * @param string $data 字符串 * @return string */ public function __construct() { $this->key = '1234567890123456'; } public function decode($str) { return openssl_decrypt(base64_decode($str),"AES-128-ECB",$this->key,OPENSSL_RAW_DATA); } /** * 加密字符串 * @param string $data 字符串 * @return string */ public function encode($str) { return base64_encode(openssl

How come I can't decrypted my AES encrypted message on someone elses AES decryptor?

筅森魡賤 提交于 2019-12-04 05:40:32
问题 from Crypto.Cipher import AES import os key = 'mysecretpassword' iv = os.urandom(16) plaintext1 = 'Secret Message A' encobj = AES.new(key, AES.MODE_CBC, iv) ciphertext1 = encobj.encrypt(plaintext1) encryptedText = ciphertext1.encode('base64') print encryptedText decobj = AES.new(key, AES.MODE_CBC, iv) print decobj.decrypt(ciphertext1) I copied the printed value of encryptedText and the key from my code and pasted to the websites below. http://www.everpassword.com/aes-encryptor http://www

Go aes encrypt / decrypt

一世执手 提交于 2019-12-04 05:36:25
问题 Having the following code package main import ( "bytes" "crypto/aes" "crypto/cipher" "crypto/rand" "encoding/base64" "io" "log" ) func main() { decrypt( "Zff9c+F3gZu/lsARvPhpMau50KUkMAie4j8MYfb12HMWhkLqZreTk8RPbtRB7RDG3QFw7Y0FXJsCq/EBEAz//XoeSZmqZXoyq2Cx8ZV+/Rw=", "u9CV7oR2w+IIk8R0hppxaw==", "~NB8CcOL#J!H?|Yr", ) text, iv := encrypt( `{"data":{"value":300}, "SEQN":700 , "msg":"IT WORKS!! }"`, "~NB8CcOL#J!H?|Yr", ) println("Encrypted", text, iv) decrypt( text, iv, "~NB8CcOL#J!H?|Yr", ) } func

Slow AES decryption in Android

∥☆過路亽.° 提交于 2019-12-04 05:34:44
问题 I tried to decrypt a 4.2 MB .dcf file using AES 128 bit key, but it took 33 seconds to decrypt (on function cipher.doFinal(data)), is it normal ? Here is a code snippet: long start = System.currentTimeMillis()/1000L; try { SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec); android.util.Log.d("TEST", "Start decoding...." + String.valueOf(length)); byte[] decrypted = cipher

AES equivalent in Ruby openssl?

人盡茶涼 提交于 2019-12-04 05:16:19
Gibberish library provides a nice CBC algo... // In Jascascript GibberishAES.enc("Made with Gibberish\n", "password"); // Outputs: "U2FsdGVkX1+21O5RB08bavFTq7Yq/gChmXrO3f00tvJaT55A5pPvqw0zFVnHSW1o" # On the command line echo "U2FsdGVkX1+21O5RB08bavFTq7Yq/gChmXrO3f00tvJaT55A5pPvqw0zFVnHSW1o" | openssl enc -d -aes-256-cbc -a -k password How can I do this decryption in ruby? The straightforward way doesn't work... require 'openssl' def aes(m,k,t) (aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc').send(m)).key = k aes.update(t) << aes.final end def encrypt(key, text) aes(:encrypt, key, text) end

StreamTransformationFilter: invalid PKCS #7 block padding found in AES decryption

风流意气都作罢 提交于 2019-12-04 05:07:36
问题 I want to use AES-256 encryption/decryption in my C++ code to do that I use cryptoPP library, I have implement encryption and decryption. but I get Error : StreamTransformationFilter: invalid PKCS #7 block padding found Error. The senario which I test is : First I encrypt myplaintext then decrypt it --> there is no error here. Second I decrypt the cipher created above --> here I got the error. I know that there are same question here but I couldn't solve my problem :( Here I set iv: byte iv

AES encryption of 16 bytes without padding

梦想与她 提交于 2019-12-04 04:44:07
问题 This should be a simple question, but I can't find any examples or figure out the answer from the openssl docs. I want to encrypt exactly 128 bits, which should fit in one encryption block. So I call EVP_EncyptInit_ex , and then what? Do I call EVP_EncryptUpdate_ex (to encrypt the 128 bit block) and EVP_EncryptFinal_ex (even though there is nothing more left to encrypt)? Or only EVP_EncryptUpdate_ex ? Or only EVP_EncryptFinal_ex ? 回答1: Here, you have already figured out the steps. So, it will

How to obtain different cipher text for same plain text using AES

为君一笑 提交于 2019-12-04 04:33:57
问题 I am currently using AesManaged class in C# to encrypt a plain text. It works fine. However, it produces the same cipher text each time it encrypts same piece of data. Is there anyway I can tweak this behavior and produce different cipher text for same piece of data? I have implemented encryption in SQL server using AES_256 algorithm and certificate. The process closely resembles with the post here: http://www.codeproject.com/Articles/662187/FIPS-Encryption-Algorithms-and-Implementation-of-A.

Android常见的加密算法

杀马特。学长 韩版系。学妹 提交于 2019-12-04 04:19:25
   Android中常见的加密算法按可逆不可逆分为两大类吧。   1.不可逆的算法   主要为MD5和SHA-1算法。   相同点:都是使用目前比较广泛的散列(Hash)函数,就是把任意长度的输入,变换成固定长度的输出,该输出就是散列值。计算的时候所有的数据都参与了运算,其中任何一个数据变化了都会导致计算出来的Hash值完全不同。(理论上来讲产生的密文都有可能产生碰撞)   不同点:MD5输出是128位的,SHA-1输出是160位的,MD5比SHA1运行速度快,SHA1比MD5强度高。MD5一般用于文件的校验,SHA-1主要使用于数字签名标准。   MD5使用: 1 public static String digest(String content){ 2 StringBuilder builder = new StringBuilder(); 3 try { 4 MessageDigest msgDitest = MessageDigest.getInstance("MD5"); 5 msgDitest.update(content.getBytes()); 6 byte[] digests = msgDitest.digest(); 7 //将每个字节转为16进制 8 for (int i=0;i<digests.length;i++){ 9 // TODO: 2019