|
|
Comments and Discussions
|
|
 |

|
This class has worked for me very well when i tested it with small strings. Once i thought this could solve my problem, i wrapped it around and integrated it in my project and then it started to expose all its bugs.
1. It doesn't decrypt huge strings! I had to use it with files with length in around 1500 characters. It did encrypt them, but failed to decrypt after a few hundred characters and gave me just junk characters.
2. It fails when you have too many symbols! I just tried it out with a string of around 100 characters with random symbols (something like : *^$&^Tou086846%^#^80%#$%@%$!$~). And all i got when decrypting was JUNK!
3. It's too much inconsistent. Okay, i first tried encrypting a string of some 1000 characters. It failed to decrypt it fully. Then i reduced the length in hundreds and finally i found it to be successfully decrypting strings with 400 characters. Then i fixed the length as 400 and started varying the characters (like different strings with length 400) and it shamefully failed at times!
This is too much unreliable to be used in any project!
Is it just me or anyone else had such problems? Or am i missing something that it isn't working for me?
|
|
|
|

|
Anyone try encrypting on Linux and then decrypting in Windows?
Results don't seem to match and I'm using the same CBC encoding (ECB doesn't work either).
If I encrypt and decrypt on Linux, it works fine...
|
|
|
|

|
Has anyone else had any problems trying to encrypted and decrypt data which has \n in it?
|
|
|
|

|
I tried to use this implementation on a non-english OS like Japanese and it doesn't decrypt properly. The same code works fine on English OS. Am I missing something?
Thanks
Raj
|
|
|
|

|
HI,
I am working with a 32 byte key. I did chage 16 with 32 in MakeKey, The result is still different when i compare with the one on c#. the PKCS7 padding i need to add. please help tp change the code.thx
|
|
|
|

|
Hi, I tried to encrypt/decrypt the ciphertext/plaintext produced by this code with openssl command line tool but with no luck. It doesn't work either way. These are my commads that I thought should work. openssl enc -aes256 -in ciphertext1.bin -out plaintext1.txt -d -K abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 -iv 00000000000000000000000000000000 -nosalt openssl enc -aes256 -in plaintext2.txt -out ciphertext2.bin -e -K abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 -iv 00000000000000000000000000000000 -nosalt My c++ code uses 32 as key and block size, the plaintext is shorter then this so I use the DecryptBlock/EncryptBlock functions. Does anyone know if it's supposed to work. Has anyone had any success on encrypting/decrypting output from this code with any other tool/implementation? Was the .Net implementations mentioned some threads below successful with other key/block sizes? Cheers Johann
|
|
|
|

|
can someone please tell me how and why are the following arrays are used in the rijndael code? the code somewhere has a comment that it is used for "round transformation". but i can't find any other souce to understand for example the values "-966564955, -126059388, -294160487, -15967960,". i guessed this is a different 'optimized' AES code... the normal AES source codes don't have the following arrays.
const int CRijndael::sm_T1[256] =
{
-966564955, -126059388, -294160487, -159679603,
-855539, -697603139, -563122255, -1849309868,
1613770832, 33620227, -832084055, 1445669757, .......................
const int CRijndael::sm_T1[256] =
const int CRijndael::sm_T8[256] =
.
.
.
const int CRijndael::sm_U1[256] =
.
.
.
const int CRijndael::sm_U4[256] =
kalmah
|
|
|
|

|
when test lines code, program don't run:
char* szDataIn=(char*)malloc(49);
szDataIn = "ababababaaaaa";
char* szDataOut = (char*)malloc(49);
oRijndael.Encrypt(szDataIn, szDataOut, 48, CRijndael::ECB);//Good
oRijndael.Decrypt(szDataOut, szDataIn, 48, CRijndael::ECB);//-->error?????
|
|
|
|
|

|
Hello All,
My Objectif is to decrypt a string already encrypted with AES using JCE ECB in Java.
Here is the class I use in java
public class DesEncrypter {
Cipher ecipher;
Cipher dcipher;
String passPhrase = "1234567890123456";
SecretKeySpec key;
DesEncrypter() throws Exception {
try {
Class providerClass = null;
try {
providerClass = Class.forName("com.sun.crypto.provider.SunJCE");
} catch (ClassNotFoundException cnfe) {
providerClass = Class.forName("com.ibm.crypto.provider.IBMJCE");
}
Security.addProvider((Provider) providerClass.newInstance());
byte[] keyBytes= new byte[16];
byte[] b= passPhrase.getBytes();
int len= b.length;
if (len > keyBytes.length) len = keyBytes.length;
System.arraycopy(b, 0, keyBytes, 0, len);
key = new SecretKeySpec(keyBytes, "AES");
ecipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
dcipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
// Prepare the parameter to the ciphers
ecipher.init(Cipher.ENCRYPT_MODE, key);
dcipher.init(Cipher.DECRYPT_MODE, key);
}/* catch (java.security.InvalidAlgorithmParameterException e) {
e.printStackTrace();
} */catch (javax.crypto.NoSuchPaddingException e) {
e.printStackTrace();
} catch (java.security.NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (java.security.InvalidKeyException e) {
e.printStackTrace();
}
}
Now using the C++ implementation of Rinjdael:
I call
void main(){
try{
CRijndael oRijndael;
oRijndael.MakeKey("1234567890123456", CRijndael::sm_chain0, 16, 16);
char szDataIn_Orig[] = "the text";
int nLen = strlen(szDataIn_Orig);
int nBlockLen = ((int)nLen / 16 + 1) * 16;
char *szDataIn = new char[nBlockLen + 1];
memset((char *)szDataIn, 0, nBlockLen + 1);
strcpy(szDataIn, szDataIn_Orig);
// To encrypt
char szDataOut[17] ="\0";
oRijndael.Encrypt(szDataIn, szDataOut, nBlockLen, CRijndael::ECB);
string encoded = base64_encode(szDataOut, nBlockLen);
printf( " Encrypted result::%s\n", convert_char_string( encoded )) ;
}
I try to encrypt with Rinjdael , and AES of JCE but I do not get the same results is there anything wrong with parameters, can anybody Help?
Ali
|
|
|
|

|
Encrypt:96E79218965EB72C92A549DD5A330112
key:670B14728AD9902A
Result(by hex):D91FB941
Correct result is(by hex): D91FB9410067766716060223966CF4226B400887DD32BBF814C03F131866A48CFCF907FA5ED4AE3225715242F22158A4
Please test!
|
|
|
|

|
Encrypt:96E79218965EB72C92A549DD5A330112
key:670B14728AD9902A
Result:D91FB941
Please test!
|
|
|
|

|
Hi,
First of all great code , thank you very much for it.
how can i use it for decrypting binary files (images - not text)
previously encrypted in .net version
|
|
|
|

|
Hi,
I need something just like this (symmetric algorithm) but my input string size can range anywhere from 1 to 60 characters. Is there some variation of this so I can use a variable length input string?
Thanks
|
|
|
|

|
How do I securely store the key so it cannot be used for malicious purposes?
Thanks
|
|
|
|

|
I saw that your implementation is fast and I'd like to use it to make an encryption DirectShow filter and to post it on this site. Do I have your approval?
|
|
|
|

|
When I compiled the sample under UNICODE, there is an error as below:
--------------------Configuration: Rijndael - Win32 Debug--------------------
Linking...
LIBCD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol _wWinMain@16
Debug/Rijndael.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Rijndael.exe - 2 error(s), 0 warning(s)
The CRijndael does work well in MFC application with Unicode, the WideCharToMultibyte() can change the string to char *.
-- modified at 6:38 Friday 7th September, 2007
|
|
|
|

|
I'm trying to reconcile the PHP encryption using ECB to get the same output but so far I'm lost on what to change in the C++ example.
My PHP code is:
$EncryptKey = "MyTestKey1234";
//Encrypt Function
function encrypt($encrypt) {
global $EncryptKey;
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$passcrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $EncryptKey, $encrypt, MCRYPT_MODE_ECB, $iv);
return bin2hex($passcrypt);
}
$pw = "teststring";
$pwe=encrypt($pw);
echo $pwe;
?>
This output gets me:
3a6013382a80e84dde2ad494220fe49916b9fc2291ec4fd4aecb6630f8ee6c35
The C++ code which I need to get the identical output is:
CRijndael oRijndael;
oRijndael.MakeKey("MyTestKey1234", CRijndael::sm_chain0, 16, 16);
char szDataIn1[] = "teststring";
char szDataIn[49];
char szDataOut[49];
memset(szDataIn, 0, 49);
memset(szDataOut, 0, 49);
//Test ECB
strcpy(szDataIn, szDataIn1);
memset(szDataOut, 0, 49);
oRijndael.Encrypt(szDataIn, szDataOut, 256, CRijndael::ECB);
CharStr2HexStr((unsigned char*)szDataOut, szHex, 32);
cout << szHex << endl;
The output from this is:
42F744073B7E2EF4BD0D21148A8082A47DA6FF3EACD5B20457B9E993DAC54FE7
What do I need to change in the C++ code to get the same as the PHP is generating?
|
|
|
|

|
I just saw this site and I am inquisitive if someone has used this under Windows Mobile SDK ?
Do you think there could be any problems in this porting ?
|
|
|
|

|
Hi!!
i m doin encryption n decryption of audio files using AES, so, tell me wat changes i have to 2 in ur project's AES algo..!! can u tell me any link where i can get some help
Faisal
|
|
|
|

|
Hi!!
i m doin encryption n decryption of audio files using AES, so, tell me wat changes i have to 2 in ur AES algo logic..!! can u tell me any link where i can get some help
Faisal
|
|
|
|

|
Hello,
I noticed that the variable member variable 't' (Line 185 in header file), is hided by a local (Automatic) variable in MakeKey. This made me think that 't' may be wrongly used in this function.
Looking on the code, there is another variable called 'tt' and the use of both may be confusing.
- The 't' is only used to copy into the round key arrays ?
- The 'tt' is only used for extrapolating ?
The varialbe 't' is incremented as a side effect of the two for loops... is this on purpose?
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|

|
If I create the following key: OP3XYvy5oCRCi8w4bYX4lA== and encrypt a string I get the following encrypted string using the Java application: Qd8S+V7twXt6bOtn/beZ7w==.
When I use this program I use the same key: OP3XYvy5oCRCi8w4bYX4lA== and the same string, but the encypted string is šC,¿‘ˆÐ<€:ÕóB”V¦-Ÿ'/.
How come they aren't the same?
|
|
|
|

|
Hi George.
Thank you for sharing the code with us, this is a great work. Now I was wondering why did you implement the CDoubleBuffering class. I understand that it is a helper that lets you use the file without bloating the code, but it also slows down the process considerably, and I think performance is always an issue with the cryptography. For instance, using a simple fread on a FILE object I was able to read an arbitrary chunk of the file and encrypt it, and it turned out to be roughly twice as fast as your CDoubleBuffering implementation. Am I missing something?
Thanks.
Mirano
Sarajevo, Bosnia
|
|
|
|

|
hello,
your implentation works fine, when i use this in a mfc app OR a command line app. but i want to use it for the encryption of the data transfer between a client and a server. the client is a mfc app. the server a command line app. if i encrypt any string with the client and decrypt it server-side, the decrypted string differs completely from the original one.
my encryption func:
try
{
CRijndael r;
r.MakeKey("12345", CRijndael::sm_chain0, 16, 16);
char in[256];
char out[256];
char text[] = "test";
ZeroMemory(&in, sizeof(in));
ZeroMemory(&out, sizeof(out));
memcpy_s(in,256+1,text,256);
r.Decrypt(in, out, 256,CRijndael::CFB);
}
catch(exception &ex)
{
MessageBox(ex.what());
}
my decryption func:
try
{
CRijndael r;
r.MakeKey("12345", CRijndael::sm_chain0, 16, 16);
char in[256];
char out[256];
char encrypted[];
ZeroMemory(&in, sizeof(in));
ZeroMemory(&out, sizeof(out));
memcpy_s(in, 256+1, encrypted,256);
r.Encrypt(in, out, 2048,CRijndael::CFB);
}
catch(exception &ex)
{
MessageBox(ex.what());
}
can anybody help me, please ?
big thanks, TSX
|
|
|
|

|
Can anybody help me on this, i used code to encrypt the code but this code is not matchin with my original data. i m having proper excrypted data with me but output of this code is not matching
|
|
|
|

|
I have tested this project and it seems that the cyphertext in CFB mode isn't standard. Other AES implementations fails to decrypt it. It doesn't happen with other 2 modes. Any idea why?
Thanks,
|
|
|
|

|
I'm trying to use this code in conjunction with a c++ xml parser (tinyxml), encrypting one value, then trying to read it in vb.net. The .net xml reader fails when reading the encrypted element, because the characters that are returned on enryption are not compatible with the xml reader.
Is it possible to modify or change which characters/characters sets are used for encrypted values?
|
|
|
|

|
Hello!
Can you tell me how to realize Rijndael encryption/decryption using CryptApi?
Do you have any example of such code?
Thanks!
|
|
|
|

|
Hi, like your article.
Trying to implement password protected program. Anyone know how to test for correct key without having to implement a public-private key system by inserting public key into input then checking for it on output? It's possible the solution is staring me in the face if it is I just didn't see it.
Thanks again to the author and any comments or solutions.
-- modified at 2:40 Sunday 2nd July, 2006
|
|
|
|

|
How would I set my own key instead of using MakeKey in this implementation? The .NET version does not support CFB cipher mode and I would like to use this class.
|
|
|
|

|
Where can I set the IV ( initialization vector ) of the algorithm?
|
|
|
|

|
Hello,
Can we use your "C++ Implementation of the Rijndael Encryption/Decryption method" for commercial puroposes without any fee restriction or any other restrictions?
I request you to respond as soon as possible.
Thanks,
Padmanabha Venkatagiri. S
|
|
|
|

|
Hi all!
I am knew to this subject. My problem is that i am getting different cipher text with the exact same code in different computers. I don't think this this normal...
Also, i am getting different cipher text with debug and release version of my program. Anyone please?
|
|
|
|

|
Is it possible for a data block encrypted by CRijndael to be decrypted by the .NET class, RijndaelManaged and vice versa? If yes, how to do that?
|
|
|
|

|
Hi, Nice article. I have been looking for an RSA encryption/decryption class with prime nr generator etc.. The Source Code that I found are to complicated and the moste of them can not handle multiprecision integers. They can only encryp with 32bit, 64bits or 512bits, prime number.
I want an simple RSA class, with the quality like your class..
Do you have such a class? I am writing my own RSA c++ implementation but it so time consuming...
thanks..
//Spinoza
|
|
|
|

|
Is there anyway we can change this code to exclude control characters such as line feed or end of line from being output from the algorithm?
At the moment, this algorithm works wonderfully but causes the output to sometimes span about 3 lines due to the control characters. This is an issue for our receiving end which reads line by line.
Any assistance will be appreciated!
Thanks
|
|
|
|

|
Hello! I'm a c++ beginner, and i'm trying to encrypt a simple text file, but, as I search in the internet, there are a lot of algorithms that I could use... so I'm a little bit confused... Can you tell me wich one is the best for me?
I need to encrypt, in a school project, using linux, and using C++. The file can be encrypted / decrypted with a Key or passhrase. Maybe using a symmetric algorithm ?
Well, I hope you could help on this..... Thanks a lot!
André Filipe
Portugal
|
|
|
|

|
Hi,
First I like your solution.
I found that in the Decrypt() function you throw an exception when we've this condition:
if(0==n || n%m_blockSize!=0)
throw exception(sm_szErrorMsg2);
I had to comment this line ofcode to make it work, so do you think this may impact anything, and is this like a bug should be fixed?
Thanks,
Maged
|
|
|
|

|
HI ALL,
I have a issue using Rijndael AES 128 bit encryption code.The code is attached along with this article for Ref:. The Issue is that on using this code i'm able to encrypt and decrypt at one go...but if i try to create seperate dlls for encrypt and decrypt the code does not work.Can anybody please let me know what the problem is...it URGENT..
My decryption code
// Retrieve attributes passed to the tag
// Write output back to the user here...
pRequest->Write( "Hello from CFX_AES_DEC! " ) ;
LPCSTR lpszVariable = pRequest->GetAttribute("decVal") ;
LPCSTR lpszEStr = pRequest->GetAttribute( "eString" );
LPCSTR lpszKey = pRequest->GetAttribute("key");
try
{
CRijndael oRijndael;
char szDataIn[49];
char szDataOut[49];
oRijndael.MakeKey(lpszKey, CRijndael::sm_chain0, 16, 16);
pRequest->Write("Input String : ");
pRequest->Write(lpszEStr);
pRequest->Write(" Key in Decryption:");
pRequest->Write( lpszKey );
memset(szDataIn, 0,49);
memset(szDataOut, 0, 49);
strcpy(szDataIn,lpszEStr);
pRequest->Write(" After strcpy() : ");
pRequest->Write(szDataIn);
//oRijndael.Decrypt((szDataIn,szDataOut);
oRijndael.Decrypt(lpszEStr,szDataOut,48,CRijndael::CBC);
pRequest->SetVariable( lpszVariable,szDataOut );
Thanks In Advance,
mustangnet
s
|
|
|
|

|
Can this implementation "encrypt in place"?
In other words, do you need to supply two buffers, or can the same buffer be used? With decryption of a large read-only encrypted file (a typical use), you don't want to use up memory for two buffers if one with work fine.
The following seemed to work, but I wanted to check:
char gen01[] =
"In the beginning "
"God created the "
"heavens and the earth."
"\0\0\0\0\0\0\0\0"
"\0\0\0\0\0\0\0\0";
#define GEN01_SIZE (sizeof(gen01))
void main()
{
CRijndael lda;
int blockSize = 16;
lda.MakeKey("abcdefghabcdefgh", "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
blockSize, blockSize);
char* szDataIn = gen01;
char* szDataOut = gen01;
int bufSize = (GEN01_SIZE / blockSize) * blockSize;
lda.Encrypt(szDataIn, szDataOut, bufSize);
lda.Decrypt(szDataOut, szDataIn, bufSize);
cout << szDataIn << endl<< endl<< endl<< endl;
}
|
|
|
|

|
I encrypted a a string 4672 characters long and found the length of the ciphered text to be 111 characters long,i got back the 4672 characters back on decrypting. what i would like to know is if the rijndeal algorithm compresses text as well.
cheers
|
|
|
|

|
can i use the code in my assignment directly?
if i use code without modified, do i have copy right problem?
thanks
kim
|
|
|
|

|
hi,,
Anyone familiar with the implementation of the AES algorithm in the below link. If u download it..
http://www.thecodeproject.com/cpp/aes.asp
in Table.h
(1.) Why have they used s boxes in ‘int’s? why not
const int CRijndael::SBox[256] rather than ---const char CRijndael::SBox[256] and replace the negative values with positive?
(2.) What does
const int CRijndael::sm_T1[256] …. const int CRijndael::sm_T8[256] tables correspond to?
(3.) and const int CRijndael::sm_U1[256]…const int CRijndael::sm_U4[256] tables correspond to
(4.) also const int CRijndael::sm_shifts[3][4][2] tables correspond to?
pls help..
Vendy
|
|
|
|

|
I am new to Rijndael encryption concept. I have got three diffrent Rijndael encryption functions including above code from. When I run each of them with the same key and same plain text, I receive diffrent cipher text.
My question is, sholud the result of diffrent implementation of the Rijndael algorithem be the same or it is possible to have diffrent result for from diffrent implementation?
As far as I undersatnd the S-Box should be same for each implementation.
|
|
|
|

|
Are there any copyright restrictions on using this code?
Ian Lewis
|
|
|
|

|
I tried using Joe Roberts code on decrypting and encrypting strings of sizes
that may not be block multiples and I noticed something. If the key contains
an ampersand(&) in the first 5-7 elements of the key, decryption text will
not be complete and will show gibberish attached to it. I replaced all
str(n)cpy functions with memcpy, thinking that this might have something
to do with it, but still the same problems. I was wondering if anyone else
came across this? I am not a very experienced programmer and would like to approach this problem.
|
|
|
|

|
Hi,
I need to encode a message with the above code and decode that encoded message
in a C#-appication.
Can anybody tell me what the correct implementation in C# is of the above code? Of course using the existing .NET Security namespaces!
Thanks in advance,
nick;
|
|
|
|

|
The code provided is compliant with windows CE?
Thanks
|
|
|
|

|
This is the first time i have used any kind of encryption routines. I would like to use this Encryption/Decryption method but im not 100% sure on what i should pass to the makeKey function. How should I create my key? For the second parameter of the MakeKey function is a 'chain' parameter. How should i decide on what the value fo this should be?
Thanks,
Andrew Shiels
PS: If you could point me to some reference materials on this it would also be appreciated
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An article presenting a C++ implementation of the Rijndael (AES) encryption/decryption method.
| Type | Article |
| Licence | Ms-PL |
| First Posted | 18 Sep 2001 |
| Views | 491,554 |
| Bookmarked | 149 times |
|
|