aes

Android JNI string encryption/decryption

╄→尐↘猪︶ㄣ 提交于 2019-12-20 05:03:32
问题 I am trying to do aes encryption/decryption in native code C. Encryption does work but when I try to decrypt the string. It doesn't end up as original string. Here is the JNI method which does encrypt/decrpt based on mode param: jbyteArray Java_com_example_hellojni_HelloJni_encrypt( JNIEnv* env, jobject this, jbyteArray srcData, jint mode) { // get length of bytes int srcLen=(*env)->GetArrayLength(env,srcData); //convert jbyteArray to byte [] jbyte data[srcLen]; (*env)->GetByteArrayRegion(env

How to get AES secret key from DH secret key

这一生的挚爱 提交于 2019-12-20 04:15:22
问题 I have the following code that converts a DH secret key to AES secret key. This used to work until Oracle JRE 8u161 when they started restricting creation of DH keys < 1024 in java.security file. Now, I will get NoSuchAlgorithmException: Unsupported secret key algorithm AES at the last line. PrivateKey privKey = null; PublicKey pubKey = null; PublicKey agreement = null; KeyAgreement keyAgreement = KeyAgreement.getInstance("DH"); keyAgreement.init(privKey); keyAgreement.doPhase(pubKey, false);

How can I encrypt/decrypt data using AES CBC+CTS (ciphertext stealing) mode in PHP?

大兔子大兔子 提交于 2019-12-20 03:27:29
问题 I have to encrypt and decrypt data in AES CTS mode (ciphertext stealing, sometimes referred as AES-XTS) in PHP to interoperate with a remote system written in .NET platform. In .NET 4, this mode is supported natively. For PHP, I cannot find a solution, based on the manual, mcrypt does not seem to have support for this mode. Could anyone please explain the difference between plain CBC and CBC-CTS? Is it possible to make the latter work in PHP with using existing modules/libraries? 回答1: This is

Block ciphers, salt, AES, MySQL, and best practices around credential storage

*爱你&永不变心* 提交于 2019-12-20 01:46:42
问题 I have a situation where I must store a password, as I am building a system to connect to another system. This other system only allows for a single user account, and the only way to connect to it is via a password. A hash is not appropriate here. I must store the password in a way that I can retrieve it. Now, with the knowledge that this is not a perfect system, I am trying to limit damage should someone get access to the database somehow. As this database will need to be used by varying

256-bit Rijndael blocksize?

会有一股神秘感。 提交于 2019-12-20 01:44:13
问题 I am trying to port a decryption routine from C# program to C++ using cryptopp, but I have a problem. In the C# program, the key and IV are both 256 bits. So I tried to do something like this: char *hash1 = "......"; std::string hash2; CryptoPP::StringSource(hash1, true,new CryptoPP::Base64Decoder(new CryptoPP::StringSink(hash2))); CryptoPP::Rijndael::Decryption decryptor(key, 32); CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( decryptor, iv); CryptoPP:

Derive a 32-byte key from a password deterministically in PHP

て烟熏妆下的殇ゞ 提交于 2019-12-19 19:43:24
问题 Today I learned that "password" tends to mean a memorizable string of an arbitrary number of characters, while "key" means a highly random string of bits (of a specific length based on the encryption algorithm used). And so today I first heard of the concept of a Key derivation function. I'm confused about how to derive a 32-byte key from a password of arbitrary length (in PHP). The following approach works but ignores the instruction of "[The salt] should be generated randomly" (so does

iPHone - AES 256 encryption without padding

被刻印的时光 ゝ 提交于 2019-12-19 12:20:29
问题 I've seen some of the posts for AES 256 encryption on iphone usign cocoa. One of the post is http://pastie.org/426530 But all the posts are using some kind of padding. How can I use AES256 encryption without using any padding? Because, I'm communicating with a server on which encryption/decryption is handled without padding. But on iphone, I can use kCCOptionPKCS7Padding or kCCOptionECBMode modes only. How can I code my iphone app so that encryption/decryption happens successfully? 回答1: Block

“Padding is invalid and cannot be removed” -Whats wrong with this code?

半腔热情 提交于 2019-12-19 09:51:09
问题 Every time I run this and encrypt, the output is variable, and when I attempt to decrypt I get "Padding is invalid and cannot be removed." Been fighting with this for a day or two now and I am at a loss. private static string strIV = "abcdefghijklmnmo"; //The initialization vector. private static string strKey = "abcdefghijklmnmoabcdefghijklmnmo"; //The key used to encrypt the text. public static string Decrypt(string TextToDecrypt) { return Decryptor(TextToDecrypt); } private static string

python aes encrypt/decrypt does not return the same results

我的未来我决定 提交于 2019-12-19 09:49:26
问题 below code sample does not return the original text after encrypt/decrypt operation and I am trying to figure it out why from Crypto.Cipher import AES text = """This is plain text to use. It should be exqctly 128 characters long to avoid padding and it is split with new lines as in file""" password = "password........" block = 32 mode = AES.MODE_CBC enc = AES.new(password, mode) encrypted = enc.encrypt(text) print "ORIGINAL: " + text print "ENCRYPTED: " + str(encrypted) print "DECRYPTED: " +

When would I choose AesCryptoServiceProvider over AesManaged or RijndaelManaged?

邮差的信 提交于 2019-12-19 05:23:46
问题 I think the distinguishing factors are AesCryptoServiceProvider is FIPS compliant AesManaged is cross-platform, requires .NET 3.0 RijndaelManaged runs on .NET 2.0, requires restricting the blocksize is that about right? 回答1: AesManaged documentation states that "The AES algorithm is essentially the Rijndael symmetric algorithm with a fixed block size and iteration count. This class functions the same way as the RijndaelManaged class but limits blocks to 128 bits and does not allow feedback