Implementation aescrypt on multiplatform

Discussion related to AES Crypt, the file encryption software for Windows, Linux, Mac, and Java.
Post Reply
rla
Posts: 6
Joined: Tue Jan 27, 2015 8:19 am

Implementation aescrypt on multiplatform

Post by rla »

I'm using aescrypt for encrypt decrypt file in windows and linux.
I try encrypt file in windows and decrypt it in linux platform and the other way round, but always got error "Error: Message has been altered or password is incorrect". i'm sure my password is correct.
I use code aescrypt windows console and linux. i try checksum file encrypted in windows and linux, the result is different.

aescrypt support encrypt decrypt multiplatform ?
User avatar
paulej
Posts: 595
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: Implementation aescrypt on multiplatform

Post by paulej »

If you encrypt the file two times, it will always be different, even on the same platform. This is part of the security.

To answer your question, though, yes, you should be able to encrypt on Windows and decrypt on Linux and vice versa.

Are you using non-ASCII characters in the password? If so, it might be a character conversion issue on Linux.

What version of Linux are you using? I can try to create the same environment.
rla
Posts: 6
Joined: Tue Jan 27, 2015 8:19 am

Re: Implementation aescrypt on multiplatform

Post by rla »

Yes, the password is non ASCII, I create a function to call function encrypt decrypt in aescrypt.c, and for the password i create function to generate it. Example "e290euowrhinjf".

I'm using this OS :
Linux Version = CentOS release 6.4 (Final) x86_64.
Windows = Windows 7 Proffesional 32 bit.

This is function to call function encrypt and decrypt.

Code: Select all

int encrypt_file(char fileName[150], char fileNameEncrypt[150]) {
	FILE *inFp;
	FILE *outFp;
	char *password;
	password=password_generator();
	inFp = fopen(fileName, "rb");
	outFp = fopen(fileNameEncrypt, "wb");
	encrypt_stream(inFp, outFp,password,strlen(password));
	fclose(inFp);
	fclose(outFp);
	return (0);
}

Code: Select all

int decrypt(char fileName[150], char fileNameDecrypt[150]) {
	FILE *inFp;
	FILE *outFp;
	char *password;
	password=password_generator();
	inFp = fopen(fileName, "rb");
	outFp = fopen(fileNameDecrypt, "wb");
	decrypt_stream(inFp, outFp,password,strlen(password));
	fclose(inFp);
	fclose(outFp);
	return (0);
}
User avatar
paulej
Posts: 595
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: Implementation aescrypt on multiplatform

Post by paulej »

I completely missed your reply. Sorry about that.

I don't think ASCII is the issue below. I think the problem is that you didn't have the password in UTF-16LE format before passing it to the function to encrypt the file. What character encoding is used by password_generator()?

I'll venture to guess it's UTF-8, since you said it has non-ASCII characters.
rla
Posts: 6
Joined: Tue Jan 27, 2015 8:19 am

Re: Implementation aescrypt on multiplatform

Post by rla »

Sorry my fault, my password ASCII.

hmm i'm new about encoding utf-8 utf-16. I read your code there a function passwd_to_utf16() on linux source code.

My password_generator just manipulation string, on linux i use char to store my password and use passwd_to_utf16() the result i save in unsigned char.

On windows same, my password_generator() just manipulation string and use wchar to store my password.

I tried encrypt file in linux and decrypt it in windows still error and vice versa.

On windows if the result from password_generator() i store in wchar, is that utf-16 or utf-8 ?
On linux, is this code correct to use your function(passwd_to_utf16()) ?

Code: Select all

int encrypt_file(char fileName[150],char fileNameEncrypt[150])
{
	FILE *inFp = NULL;
        FILE *outFp = NULL;
	char *password;
	int passlen=0;
        unsigned char pass[MAX_PASSWD_BUF];
	password=password_generator();
	passlen = passwd_to_utf16((unsigned char*)password,strlen((char *)password),MAX_PASSWD_LEN,pass);
	inFp=fopen(fileName,"rb");
	outFp=fopen(fileNameEncrypt,"wb");
	encrypt_stream(inFp, outFp,pass,passlen);
	fclose(inFp);
	fclose(outFp);
	return (0);
}
Thanks.
User avatar
paulej
Posts: 595
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: Implementation aescrypt on multiplatform

Post by paulej »

If you're using ASCII, the simplest thing is to effectively do what you're doing on Windows: put characters inside wchar_t.

In a char array, if you have the password "abc" (0x61 0x62 0x63, you turn that into 0x61 0x00 0x62 0x00 0x63 0x00 to be in UTF-16LE format. Just put 0x00 after each character. That should then work and be compatible with the way the current AES Crypt code handles passwords.

You'll also note that when calling encrypt_stream(), the length of the password (passlen) would be 6 for "abc". It's a count of octets, not a count of characters.
rla
Posts: 6
Joined: Tue Jan 27, 2015 8:19 am

Re: Implementation aescrypt on multiplatform

Post by rla »

Thank you, i use wchar to store my password on windows, and on linux i use char to store my password and add 0x00 after each character, it work. no error show up and the file not corrupt.
But i want to ask about wchar_t, the file can be encrypt/decrypt when i put 14 password length on windows and i put 28 password length on linux. my password is 14 character. is there a different between wchar_t and char ?
User avatar
paulej
Posts: 595
Joined: Sun Aug 23, 2009 7:32 pm
Location: Research Triangle Park, NC, USA
Contact:

Re: Implementation aescrypt on multiplatform

Post by paulej »

wchar_t is 16 bits (two bytes), whereas char is one byte. That would explain why the length values might be different. I've not looked at the Windows code in a while, but I assume the function is expecting a length in "characters". These two functions between Windows and Linux ought to be consistent, but I guess they're not. Regardless, the end result is the same.
rla
Posts: 6
Joined: Tue Jan 27, 2015 8:19 am

Re: Implementation aescrypt on multiplatform

Post by rla »

ya, file not corrupted. i try encrypt from windows and decrypt it on linux and vice versa. btw thanks for your help, i already implement aescrypt on my c project. i try some library to encrypt/decrypt file, but aescrypt faster than other lib for large file.
Post Reply