f



AES encrypt/decrypt help please

Hi,
I am trying to encrypt some text files with AES or similar encoding via 
a windows batch file, and then upload them to my server, then decode 
them with php, so I can enter the data within the files into my sql 
database.
Reason for the encryption is that the files are uploaded into a semi 
public folder, and I don't want anyone else who has access to that 
folder to be able to read the data from the files.

Anyway.. I have encrypted a file using ccrypt, uploaded this to the 
server, but using mcrypt in php I am getting garbage out.. I'm sure it 
is something to do with the IV string, but I can't seem to get the value 
for this out of the ccrypt encoded file..

Has anyone ever done a similar thing..?? any suggestions for something 
that might work..

What I need is a simple encryption that will run from a batch file or 
even from a VB script on windows pc, that I can decode easily using 
mcrypt in php on the server..

As you can probably tell... I'm not well up on this...!!!!

Any help would be most gratefully received..

Thanks
Andy
0
Andy
3/27/2010 3:26:29 PM
comp.lang.php 32643 articles. 0 followers. Post Follow

9 Replies
897 Views

Similar Articles

[PageSpeed] 36

On Mar 27, 10:26=A0am, Andy <str_...@hotmail.com> wrote:
> Hi,
> I am trying to encrypt some text files with AES or similar encoding via
> a windows batch file, and then upload them to my server, then decode
> them with php, so I can enter the data within the files into my sql
> database.
> Reason for the encryption is that the files are uploaded into a semi
> public folder, and I don't want anyone else who has access to that
> folder to be able to read the data from the files.
>
> Anyway.. I have encrypted a file using ccrypt, uploaded this to the
> server, but using mcrypt in php I am getting garbage out.. I'm sure it
> is something to do with the IV string, but I can't seem to get the value
> for this out of the ccrypt encoded file..
>
> Has anyone ever done a similar thing..?? any suggestions for something
> that might work..
>
> What I need is a simple encryption that will run from a batch file or
> even from a VB script on windows pc, that I can decode easily using
> mcrypt in php on the server..
>
> As you can probably tell... I'm not well up on this...!!!!
>
> Any help would be most gratefully received..
>
> Thanks
> Andy

Maybe you could post a sample base64 encoded encrypted string and the
PHP program you're using to do the decryption?

According to wikipedia.org's entry on ccrypt, "ccrypt is based on the
Rijndael cypher, the same cipher used in the AES standard. However, in
the AES standard a 128-bit block size is used, whereas ccrypt uses a
256-bit block size.".  Per that, you'd need to be using
MCRYPT_RIJNDAEL_256.  It's also possible you're not using the correct
mode.  Maybe they're using CBC mode and you're using ECB or
something.  Another possibility: you're doing everything correctly but
ccrypt is employing compression, as well.

Also, if you find mcrypt to be unintuitive, you may find phpseclib's
Crypt_Rijndael to be more intuitive:

http://phpseclib.sourceforge.net/

<?php
$aes =3D new Crypt_Rijndael();
$aes->setBlockSize(256);
$aes->setKey(...);
$aes->setIV(...);

echo $aes->decrypt();
?>
0
yawnmoth
3/27/2010 11:38:47 PM
In article 
<bd25fae1-f6c1-40ce-b42d-dcbf910b461a@t23g2000yqt.googlegroups.com>,
 yawnmoth <terra1024@yahoo.com> wrote:

> On Mar 27, 10:26�am, Andy <str_...@hotmail.com> wrote:
> > Hi,
> > I am trying to encrypt some text files with AES or similar encoding via
> > a windows batch file, and then upload them to my server, then decode
> > them with php, so I can enter the data within the files into my sql
> > database.
> > Reason for the encryption is that the files are uploaded into a semi
> > public folder, and I don't want anyone else who has access to that
> > folder to be able to read the data from the files.
> >
> > Anyway.. I have encrypted a file using ccrypt, uploaded this to the
> > server, but using mcrypt in php I am getting garbage out.. I'm sure it
> > is something to do with the IV string, but I can't seem to get the value
> > for this out of the ccrypt encoded file..
> >
> > Has anyone ever done a similar thing..?? any suggestions for something
> > that might work..
> >
> > What I need is a simple encryption that will run from a batch file or
> > even from a VB script on windows pc, that I can decode easily using
> > mcrypt in php on the server..
> >
> > As you can probably tell... I'm not well up on this...!!!!
> >
> > Any help would be most gratefully received..
> >
> > Thanks
> > Andy
> 
> Maybe you could post a sample base64 encoded encrypted string and the
> PHP program you're using to do the decryption?
> 
> According to wikipedia.org's entry on ccrypt, "ccrypt is based on the
> Rijndael cypher, the same cipher used in the AES standard. However, in
> the AES standard a 128-bit block size is used, whereas ccrypt uses a
> 256-bit block size.".  Per that, you'd need to be using
> MCRYPT_RIJNDAEL_256.  It's also possible you're not using the correct
> mode.  Maybe they're using CBC mode and you're using ECB or
> something.  Another possibility: you're doing everything correctly but
> ccrypt is employing compression, as well.
> 
> Also, if you find mcrypt to be unintuitive, you may find phpseclib's
> Crypt_Rijndael to be more intuitive:
> 
> http://phpseclib.sourceforge.net/
> 
> <?php
> $aes = new Crypt_Rijndael();
> $aes->setBlockSize(256);
> $aes->setKey(...);
> $aes->setIV(...);
> 
> echo $aes->decrypt();
> ?>

Hi, Many many thanks for your help...
I have attached 2 files, the csv file unencoded and the ccrypt encoded 
file, I'm pretty sure the mode is CBC,it's Rijndael 256 and we have been 
using MCRYPT_RIJNDAEL_256 to try to decode it, but so far have only got 
garbage out...
Best regards
Andy
[DatabaseName],claimform,,,,,,,,,,,,,,,,
gfkhdf,khgdkghd,khgd,khgd,khgdkghd,khgdk,hgdkh,gdkhg,dkhg,dkh,tdkh,gd,khgdty,dytdh,gdTDtkhdhgdGHDD,GHDGH,DKHGD,HKGD
JVVGHJGVjlhvjlhvhjvLHVjhv,jhvljhv,jhv,jhv,jhv,jhvjhvhj,vgc,tydty,fluy,fjh,fuyd,"td,jh",fluyrfu,fyjh,fjy,fd,jfc,jy

begin 644 claimform.csv.cpt
M:'DC,ZU?27VEDGZ#9,B0`!#,2=^V!HJSD,SG,%P2G)L`B!^K]]>FQ-'?4WYU
M@:'H#\*I-[\BO(],OE;%_)7)TAS2#:?:CXBFL)D&"?*<OWP4`SLHYN7>YQ3J
M:"2?NS(5>G@CX7PG0.,F0'EE[M\AU/^`T"9&&BR"[,4M2CE@?_GG=FWO6"&Z
M'_7HI%MW9;),[?BMNVHGQ?$!FCI/CG'8\G>T7U\5)M`Z?'531%UQO3Q(<R21
M[8VVW7/-3:&-R',%2;"W'5AW:#)8;ORR1VT/G/U=(%+!M+($F#LDAO!Z([/<
MC]CM=T?J*.SC7Y9[)!W#G6_1!9><3S(8+RY@KM$,TV?+AO`\=E5-/*2>E9-_
D73LN"$YM^#7M\>(K["T[O-9JW[T-UC2YGN)KUD1S<IDA#5BI
`
end
0
Andy
3/28/2010 12:17:24 PM
In article <str_343-0141EA.12172428032010@news.newsguy.com>,
 Andy <str_343@hotmail.com> wrote:

> In article 
> <bd25fae1-f6c1-40ce-b42d-dcbf910b461a@t23g2000yqt.googlegroups.com>,
>  yawnmoth <terra1024@yahoo.com> wrote:
> 
> > On Mar 27, 10:26�am, Andy <str_...@hotmail.com> wrote:
> > > Hi,
> > > I am trying to encrypt some text files with AES or similar encoding via
> > > a windows batch file, and then upload them to my server, then decode
> > > them with php, so I can enter the data within the files into my sql
> > > database.
> > > Reason for the encryption is that the files are uploaded into a semi
> > > public folder, and I don't want anyone else who has access to that
> > > folder to be able to read the data from the files.
> > >
> > > Anyway.. I have encrypted a file using ccrypt, uploaded this to the
> > > server, but using mcrypt in php I am getting garbage out.. I'm sure it
> > > is something to do with the IV string, but I can't seem to get the value
> > > for this out of the ccrypt encoded file..
> > >
> > > Has anyone ever done a similar thing..?? any suggestions for something
> > > that might work..
> > >
> > > What I need is a simple encryption that will run from a batch file or
> > > even from a VB script on windows pc, that I can decode easily using
> > > mcrypt in php on the server..
> > >
> > > As you can probably tell... I'm not well up on this...!!!!
> > >
> > > Any help would be most gratefully received..
> > >
> > > Thanks
> > > Andy
> > 
> > Maybe you could post a sample base64 encoded encrypted string and the
> > PHP program you're using to do the decryption?
> > 
> > According to wikipedia.org's entry on ccrypt, "ccrypt is based on the
> > Rijndael cypher, the same cipher used in the AES standard. However, in
> > the AES standard a 128-bit block size is used, whereas ccrypt uses a
> > 256-bit block size.".  Per that, you'd need to be using
> > MCRYPT_RIJNDAEL_256.  It's also possible you're not using the correct
> > mode.  Maybe they're using CBC mode and you're using ECB or
> > something.  Another possibility: you're doing everything correctly but
> > ccrypt is employing compression, as well.
> > 
> > Also, if you find mcrypt to be unintuitive, you may find phpseclib's
> > Crypt_Rijndael to be more intuitive:
> > 
> > http://phpseclib.sourceforge.net/
> > 
> > <?php
> > $aes = new Crypt_Rijndael();
> > $aes->setBlockSize(256);
> > $aes->setKey(...);
> > $aes->setIV(...);
> > 
> > echo $aes->decrypt();
> > ?>
> 
> Hi, Many many thanks for your help...
> I have attached 2 files, the csv file unencoded and the ccrypt encoded 
> file, I'm pretty sure the mode is CBC,it's Rijndael 256 and we have been 
> using MCRYPT_RIJNDAEL_256 to try to decode it, but so far have only got 
> garbage out...
> Best regards
> Andy
> [DatabaseName],claimform,,,,,,,,,,,,,,,,
> gfkhdf,khgdkghd,khgd,khgd,khgdkghd,khgdk,hgdkh,gdkhg,dkhg,dkh,tdkh,gd,khgdty,d
> ytdh,gdTDtkhdhgdGHDD,GHDGH,DKHGD,HKGD
> JVVGHJGVjlhvjlhvhjvLHVjhv,jhvljhv,jhv,jhv,jhv,jhvjhvhj,vgc,tydty,fluy,fjh,fuyd
> ,"td,jh",fluyrfu,fyjh,fjy,fd,jfc,jy
> 
> begin 644 claimform.csv.cpt
> [Image]
> 
> end

Key is abc123 ..!
0
Andy
3/28/2010 12:38:55 PM
"Andy" <str_343@hotmail.com> wrote in message 
news:str_343-0141EA.12172428032010@news.newsguy.com...

> I have attached 2 files

There is no point in attaching files to non-binary newsgroups. They get 
stripped, 


0
rf
3/28/2010 1:41:18 PM
In article <20Jrn.15698$pv.15179@news-server.bigpond.net.au>,
 "rf" <rf@z.invalid> wrote:

> "Andy" <str_343@hotmail.com> wrote in message 
> news:str_343-0141EA.12172428032010@news.newsguy.com...
> 
> > I have attached 2 files
> 
> There is no point in attaching files to non-binary newsgroups. They get 
> stripped, 

whoops sorry.. I'm new to this...!
0
Andy
3/28/2010 1:56:41 PM
Ok lets try this again again....:-
I do apologise for my previous efforts

This is the csv file before encoding with ccrypt:-

[DatabaseName],claimform,,,,,,,,,,,,,,,,
gfkhdf,khgdkghd,khgd,khgd,khgdkghd,khgdk,hgdkh,gdkhg,dkhg,dkh,tdkh,gd,khg
dty,dytdh,gdTDtkhdhgdGHDD,GHDGH,DKHGD,HKGD
JVVGHJGVjlhvjlhvhjvLHVjhv,jhvljhv,jhv,jhv,jhv,jhvjhvhj,vgc,tydty,fluy,fjh
,fuyd,"td,jh",fluyrfu,fyjh,fjy,fd,jfc,jy


This is the encoded file encrypted with ccrypt using RIJNDAEL_256 in CBC 
mode (I have base 64 encoded it after encryption)

aHkjM+KJoF9JfeKAosOtfsOJZMK7w6oAEMODSe+sguKIggbDpOKJpcOqw4PDgTBcEsO6w7UAw
6AfwrTLnOKXisK2xpLigJTvrIJTfnXDhcKww4sPwqzCqTfDuCLCusOoTMOmVuKJiMK4w6/igK
bigJwc4oCcCsOf4oGEw6jDoMK24oiew7QGCcOaw7rDuHwUAzsow4rDgu+sgcOBFMONaCTDvMK
qMhV6eCPCt3wnQOKAniZAeWXDk++sgiHigJjLh8OE4oCTJkYaLMOHw4/iiYgtSjlgf8uYw4F2
bcOUWCHiiKsfxLHDi8KnW3dl4omkTMOMwq/iiaDCqmon4omIw5IBw7Y6T8OpccO/w5p3wqVfX
xUm4oCTOnx1U0Rdcc6pPEhzJMOrw4zDp+KIguKAunPDlU3CsMOnwrtzBUniiJ7iiJEdWHdoMl
huwrjiiaRHbQ/DusudXSBSwqHCpeKJpATDsjskw5zvo796I+KJpeKAucOow7/DjHdHw40ow4/
igJ5fw7F7JB3iiJrDuW/igJQFw7PDuk8yGC8uYMOG4oCUDOKAnWfDgMOc76O/PHZVTTzCp8O7
w6/DrH9dOy4ITm3CrzXDjMOS4oCaK8OPLTvCusO3au+sgs6pCsO3NM+Aw7vigJprw7dEc3LDt
CEKWMKp


the key is abc123

Many thanks
0
Andy
3/28/2010 3:43:01 PM
On Mar 28, 10:43=A0am, Andy <str_...@hotmail.com> wrote:
> Ok lets try this again again....:-
> I do apologise for my previous efforts
>
> This is the csv file before encoding with ccrypt:-
>
> [DatabaseName],claimform,,,,,,,,,,,,,,,,
> gfkhdf,khgdkghd,khgd,khgd,khgdkghd,khgdk,hgdkh,gdkhg,dkhg,dkh,tdkh,gd,khg
> dty,dytdh,gdTDtkhdhgdGHDD,GHDGH,DKHGD,HKGD
> JVVGHJGVjlhvjlhvhjvLHVjhv,jhvljhv,jhv,jhv,jhv,jhvjhvhj,vgc,tydty,fluy,fjh
> ,fuyd,"td,jh",fluyrfu,fyjh,fjy,fd,jfc,jy
>
> This is the encoded file encrypted with ccrypt using RIJNDAEL_256 in CBC
> mode (I have base 64 encoded it after encryption)
>
> aHkjM+KJoF9JfeKAosOtfsOJZMK7w6oAEMODSe+sguKIggbDpOKJpcOqw4PDgTBcEsO6w7UAw
> 6AfwrTLnOKXisK2xpLigJTvrIJTfnXDhcKww4sPwqzCqTfDuCLCusOoTMOmVuKJiMK4w6/igK
> bigJwc4oCcCsOf4oGEw6jDoMK24oiew7QGCcOaw7rDuHwUAzsow4rDgu+sgcOBFMONaCTDvMK
> qMhV6eCPCt3wnQOKAniZAeWXDk++sgiHigJjLh8OE4oCTJkYaLMOHw4/iiYgtSjlgf8uYw4F2
> bcOUWCHiiKsfxLHDi8KnW3dl4omkTMOMwq/iiaDCqmon4omIw5IBw7Y6T8OpccO/w5p3wqVfX
> xUm4oCTOnx1U0Rdcc6pPEhzJMOrw4zDp+KIguKAunPDlU3CsMOnwrtzBUniiJ7iiJEdWHdoMl
> huwrjiiaRHbQ/DusudXSBSwqHCpeKJpATDsjskw5zvo796I+KJpeKAucOow7/DjHdHw40ow4/
> igJ5fw7F7JB3iiJrDuW/igJQFw7PDuk8yGC8uYMOG4oCUDOKAnWfDgMOc76O/PHZVTTzCp8O7
> w6/DrH9dOy4ITm3CrzXDjMOS4oCaK8OPLTvCusO3au+sgs6pCsO3NM+Aw7vigJprw7dEc3LDt
> CEKWMKp
>
> the key is abc123
>
> Many thanks

alternatively you could use php on your local machine to encrypt the
files, this might make it easier to ensure your encrypt and decrypt
functions are compatable
0
Eric
3/29/2010 2:53:29 PM
Il 28/03/2010 0.38, yawnmoth ha scritto:
> On Mar 27, 10:26 am, Andy <str_...@hotmail.com> wrote:
>> Hi,
>> I am trying to encrypt some text files with AES or similar encoding via
>> a windows batch file, and then upload them to my server, then decode
>> them with php, so I can enter the data within the files into my sql

> Also, if you find mcrypt to be unintuitive, you may find phpseclib's
> Crypt_Rijndael to be more intuitive:
> 
> http://phpseclib.sourceforge.net/
> 
is very very very slow, openssl have a multiple bug
impossible crypt decript and sign

0
Gufo
4/14/2010 8:58:24 PM
On Apr 14, 3:58=A0pm, Gufo Rosso <spaaaaaamaaa...@libero.it> wrote:
> Il 28/03/2010 0.38, yawnmoth ha scritto:
>
> > On Mar 27, 10:26 am, Andy <str_...@hotmail.com> wrote:
> >> Hi,
> >> I am trying to encrypt some text files with AES or similar encoding vi=
a
> >> a windows batch file, and then upload them to my server, then decode
> >> them with php, so I can enter the data within the files into my sql
> > Also, if you find mcrypt to be unintuitive, you may find phpseclib's
> > Crypt_Rijndael to be more intuitive:
>
> >http://phpseclib.sourceforge.net/
>
> is very very very slow, openssl have a multiple bug
> impossible crypt decript and sign

Slow as though phpseclib's Crypt_AES may be it is worthwhile to point
out that it's also the fastest pure-PHP implementation around, per
this:

http://phpseclib.sourceforge.net/documentation/sym_crypt.html#sym_crypt_aes=
_benchmarks

It even manages to beat this implementation by quite a bit:

https://wiki.secondlife.com/wiki/Talk:AES_PHP_Implementation

And that's when mcrypt isn't available - when mcrypt is available
it'll use that and get even faster.

And as for "impossible crypt decript and sign"...  you're right.  AES
cannot be used for signing.  If you want to sign something, use RSA.
Or maybe HMACs, which are supposed to be the symmetric key analog to
signatures.  To use AES to create and verify signatures makes about as
much sense as using OpenSSL to render an animated GIF.
0
yawnmoth
4/15/2010 5:51:19 AM
Reply: