The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
Jiggmin <mrjigg... @gmail.com>
Date: Tue, 9 Dec 2008 21:58:50 -0800 (PST)
Local: Wed, Dec 10 2008 12:58 am
Subject: As3Crypto + PHP
There are a bunch of posts about Crypto to not matching up with the
encryption in other languages. Bummer. Here's what I ended up with:
Algorithm: RIJNDAEL (AES) 128
Mode: CBC
Key: b86b2979310c6833d15cebefdce659cf
Padding: Null characters (char code 0)
IV: none
String to be encrypted: "test"
encrypted with Crypto: rYksPO4+x3STIhYONGPDXA==
encrypted with php: rYksPO4+x3STIhYONGPDXA==
String to be encrypted: "test with a longer string woooweies what
fun."
encrypted with Crypto: 3El/G+nYOStYg1UyrK1kboBXW8oRJr6WtkYsWzZx6Rx/
A5J0178hm/TcAtGe01aD
encrypted with php: 3El/G
+nYOStYg1UyrK1kbqfWIyLlAq0WKmQewKuTvCXaEZ88YY1Xxl5fI3f2ztYE
The first twenty something characters of the encrypted strings match,
but they don't match after that. So, this actually would work if you
only had to send very short strings back and fourth. (hehe)
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jiggmin <mrjigg... @gmail.com>
Date: Wed, 10 Dec 2008 21:26:34 -0800 (PST)
Local: Thurs, Dec 11 2008 12:26 am
Subject: Re: As3Crypto + PHP
Aww man! I had confused CBC with ECB. Encryption works perfectly
between php and Crypto now. The only thing you have to do is make a
pad class that pads the byte array with null bytes, because that's
what php does automatically. You can get a null byte in as3 with
String.fromCharCode(0);
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Mehmet Ecevit <mece... @gmail.com>
Date: Thu, 11 Dec 2008 07:23:43 -0800 (PST)
Local: Thurs, Dec 11 2008 10:23 am
Subject: Re: As3Crypto + PHP
Did you solve the problem?
On Dec 11, 7:26 am, Jiggmin <mrjigg... @gmail.com> wrote:
> Aww man! I had confused CBC with ECB. Encryption works perfectly
> between php and Crypto now. The only thing you have to do is make a
> pad class that pads the byte array with null bytes, because that's
> what php does automatically. You can get a null byte in as3 with
> String.fromCharCode(0);
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Jason Foglia" <jason.fog... @gmail.com>
Date: Thu, 11 Dec 2008 08:47:24 -0700
Local: Thurs, Dec 11 2008 10:47 am
Subject: Re: [as3crypto] Re: As3Crypto + PHP
Do you have both php and as3Crypto examples?
How much padding is needed?
On Wed, Dec 10, 2008 at 10:26 PM, Jiggmin <mrjigg
... @gmail.com> wrote:
> Aww man! I had confused CBC with ECB. Encryption works perfectly
> between php and Crypto now. The only thing you have to do is make a
> pad class that pads the byte array with null bytes, because that's
> what php does automatically. You can get a null byte in as3 with
> String.fromCharCode(0);
--
Jason Foglia
Work:
Educational Sales Co.
Web Applications Developer
ja... @escobooks.com
(800) 999-5199
Personal:
(480) 255-5062
http://jaysart.com
jason.fog... @gmail.com
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
zigityzig <greg_b... @cox.net>
Date: Fri, 12 Dec 2008 16:07:00 -0800 (PST)
Subject: Re: As3Crypto + PHP
This is what I found too if you don't provide PHP mcrypt with an
initialization vector or provide it with one of all zero's the first
block is not XORed with the initialization vector.
Any additional blocks are XORed with the prior. This and the padding
method are what create the compatibility problems. Padding the string
prior to encryption also solves this as long as the flash client knows
what character you used for padding. PHP mcrypt pads with null or the
zero ascii character which causes some issues when decrypting in the
flash client
In the class I wrote as long as I use PHP mcrypt with an
initialization vector of all zero's the output is identical. I pad
strings prior to encryption with a known character like so
//PAD STRING PRIOR TO ENCRYPTION
if(strlen($string) % 16){
$string = str_pad($string, ceil(strlen($string)/16)*16,"~");
}
On Dec 9, 9:58 pm, Jiggmin <mrjigg
... @gmail.com> wrote:
> There are a bunch of posts about Crypto to not matching up with the
> encryption in other languages. Bummer. Here's what I ended up with:
> Algorithm: RIJNDAEL (AES) 128
> Mode: CBC
> Key: b86b2979310c6833d15cebefdce659cf
> Padding: Null characters (char code 0)
> IV: none
> String to be encrypted: "test"
> encrypted with Crypto: rYksPO4+x3STIhYONGPDXA==
> encrypted with php: rYksPO4+x3STIhYONGPDXA==
> String to be encrypted: "test with a longer string woooweies what
> fun."
> encrypted with Crypto: 3El/G+nYOStYg1UyrK1kboBXW8oRJr6WtkYsWzZx6Rx/
> A5J0178hm/TcAtGe01aD
> encrypted with php: 3El/G
> +nYOStYg1UyrK1kbqfWIyLlAq0WKmQewKuTvCXaEZ88YY1Xxl5fI3f2ztYE
> The first twenty something characters of the encrypted strings match,
> but they don't match after that. So, this actually would work if you
> only had to send very short strings back and fourth. (hehe)
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Jason <jason.fog... @gmail.com>
Date: Mon, 15 Dec 2008 15:11:20 -0800 (PST)
Local: Mon, Dec 15 2008 6:11 pm
Subject: Re: As3Crypto + PHP
Here it goes.
I have spent alot of time on this and found no other way.
No one else had examples so here is goes.
package
{
import flash.display.Sprite;
import flash.utils.ByteArray;
import com.hurlant.crypto.symmetric.ICipher;
import com.hurlant.crypto.symmetric.IVMode;
import com.hurlant.crypto.symmetric.IMode;
import com.hurlant.crypto.symmetric.NullPad;
import com.hurlant.crypto.symmetric.PKCS5;
import com.hurlant.crypto.symmetric.IPad;
import com.hurlant.util.Base64;
import com.hurlant.util.Hex;
import com.hurlant.crypto.Crypto;
public class CryptoCode extends Sprite
{
private var type:String='simple-des-ecb';
private var key:ByteArray;
public function CryptoCode()
{
init();
}
private function init():void
{
key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
characters long
trace(encrypt('TEST TEST'));
trace(decrypt(encrypt('TEST TEST'));
}
private function encrypt(txt:String = ''):String
{
var data:ByteArray = Hex.toArray(Hex.fromString(txt));
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(type, key, pad);
pad.setBlockSize(mode.getBlockSize());
mode.encrypt(data);
return Base64.encodeByteArray(data);
}
private function decrypt(txt:String = ''):String
{
var data:ByteArray = Base64.decodeToByteArray(txt);
var pad:IPad = new PKCS5;
var mode:ICipher = Crypto.getCipher(type, key, pad);
pad.setBlockSize(mode.getBlockSize());
mode.decrypt(data);
return Hex.toString(Hex.fromArray(data));
}
}
}
<?
class Crypt
{
var $key = NULL;
var $iv = NULL;
var $iv_size = NULL;
function Crypt()
{
$this->init();
}
function init($key = "")
{
$this->key = ($key != "") ? $key : "";
$this->algorithm = MCRYPT_DES;
$this->mode = MCRYPT_MODE_ECB;
$this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
$this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
}
function encrypt($data)
{
$size = mcrypt_get_block_size($this->algorithm, $this->mode);
$data = $this->pkcs5_pad($data, $size);
return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
$data, $this->mode, $this->iv));
}
function decrypt($data)
{
return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
$this->key, base64_decode($data), $this->mode, $this->iv)));
}
function pkcs5_pad($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function pkcs5_unpad($text)
{
$pad = ord($text{strlen($text)-1});
if ($pad > strlen($text)) return false;
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
false;
return substr($text, 0, -1 * $pad);
}
}
?>
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
kleelof <klee... @yahoo.com>
Date: Sat, 27 Dec 2008 15:59:38 -0800 (PST)
Local: Sat, Dec 27 2008 6:59 pm
Subject: Re: As3Crypto + PHP
Hello,
I've tried using this library, but I always get an error from the
base64 part that says constructors can only be declared public. If I
change it to public, I get another error.
I am using CS3. Can these files only be used in FLEX? I downloaded
both the source code, which I am attempting to use now, and the SWC
which I cannot figure out how to install since it did not come in an
installer packge.
take care,
lee
On Dec 16, 6:11 am, Jason <jason.fog... @gmail.com> wrote:
> Here it goes.
> I have spent alot of time on this and found no other way.
> No one else had examples so here is goes.
> package
> {
> import flash.display.Sprite;
> import flash.utils.ByteArray;
> import com.hurlant.crypto.symmetric.ICipher;
> import com.hurlant.crypto.symmetric.IVMode;
> import com.hurlant.crypto.symmetric.IMode;
> import com.hurlant.crypto.symmetric.NullPad;
> import com.hurlant.crypto.symmetric.PKCS5;
> import com.hurlant.crypto.symmetric.IPad;
> import com.hurlant.util.Base64;
> import com.hurlant.util.Hex;
> import com.hurlant.crypto.Crypto;
> public class CryptoCode extends Sprite
> {
> private var type:String='simple-des-ecb';
> private var key:ByteArray;
> public function CryptoCode()
> {
> init();
> }
> private function init():void
> {
> key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
> characters long
> trace(encrypt('TEST TEST'));
> trace(decrypt(encrypt('TEST TEST'));
> }
> private function encrypt(txt:String = ''):String
> {
> var data:ByteArray = Hex.toArray(Hex.fromString(txt));
> var pad:IPad = new PKCS5;
> var mode:ICipher = Crypto.getCipher(type, key, pad);
> pad.setBlockSize(mode.getBlockSize());
> mode.encrypt(data);
> return Base64.encodeByteArray(data);
> }
> private function decrypt(txt:String = ''):String
> {
> var data:ByteArray = Base64.decodeToByteArray(txt);
> var pad:IPad = new PKCS5;
> var mode:ICipher = Crypto.getCipher(type, key, pad);
> pad.setBlockSize(mode.getBlockSize());
> mode.decrypt(data);
> return Hex.toString(Hex.fromArray(data));
> }
> }
> }
> <?
> class Crypt
> {
> var $key = NULL;
> var $iv = NULL;
> var $iv_size = NULL;
> function Crypt()
> {
> $this->init();
> }
> function init($key = "")
> {
> $this->key = ($key != "") ? $key : "";
> $this->algorithm = MCRYPT_DES;
> $this->mode = MCRYPT_MODE_ECB;
> $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
> $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
> }
> function encrypt($data)
> {
> $size = mcrypt_get_block_size($this->algorithm, $this->mode);
> $data = $this->pkcs5_pad($data, $size);
> return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
> $data, $this->mode, $this->iv));
> }
> function decrypt($data)
> {
> return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
> $this->key, base64_decode($data), $this->mode, $this->iv)));
> }
> function pkcs5_pad($text, $blocksize)
> {
> $pad = $blocksize - (strlen($text) % $blocksize);
> return $text . str_repeat(chr($pad), $pad);
> }
> function pkcs5_unpad($text)
> {
> $pad = ord($text{strlen($text)-1});
> if ($pad > strlen($text)) return false;
> if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
> false;
> return substr($text, 0, -1 * $pad);
> }}
> ?>
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"corbo... @yahoo.com" <corbo... @yahoo.com>
Date: Sat, 3 Jan 2009 18:44:57 -0800 (PST)
Local: Sat, Jan 3 2009 9:44 pm
Subject: Re: As3Crypto + PHP
I had problems making this work with PHP as well so i wrote a AES data-
service to connect with PHP which uses javascript to encrypt and
decrypt on the flex end. It works great and is all set up with
functions on each end so it takes less then 3 lines of action-script
and PHP to use it
On Dec 27 2008, 6:59 pm, kleelof <klee... @yahoo.com> wrote:
> Hello,
> I've tried using this library, but I always get an error from the
> base64 part that says constructors can only be declared public. If I
> change it to public, I get another error.
> I am using CS3. Can these files only be used in FLEX? I downloaded
> both the source code, which I am attempting to use now, and the SWC
> which I cannot figure out how to install since it did not come in an
> installer packge.
> take care,
> lee
> On Dec 16, 6:11 am, Jason <jason.fog... @gmail.com> wrote:
> > Here it goes.
> > I have spent alot of time on this and found no other way.
> > No one else had examples so here is goes.
> > package
> > {
> > import flash.display.Sprite;
> > import flash.utils.ByteArray;
> > import com.hurlant.crypto.symmetric.ICipher;
> > import com.hurlant.crypto.symmetric.IVMode;
> > import com.hurlant.crypto.symmetric.IMode;
> > import com.hurlant.crypto.symmetric.NullPad;
> > import com.hurlant.crypto.symmetric.PKCS5;
> > import com.hurlant.crypto.symmetric.IPad;
> > import com.hurlant.util.Base64;
> > import com.hurlant.util.Hex;
> > import com.hurlant.crypto.Crypto;
> > public class CryptoCode extends Sprite
> > {
> > private var type:String='simple-des-ecb';
> > private var key:ByteArray;
> > public function CryptoCode()
> > {
> > init();
> > }
> > private function init():void
> > {
> > key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
> > characters long
> > trace(encrypt('TEST TEST'));
> > trace(decrypt(encrypt('TEST TEST'));
> > }
> > private function encrypt(txt:String = ''):String
> > {
> > var data:ByteArray = Hex.toArray(Hex.fromString(txt));
> > var pad:IPad = new PKCS5;
> > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > pad.setBlockSize(mode.getBlockSize());
> > mode.encrypt(data);
> > return Base64.encodeByteArray(data);
> > }
> > private function decrypt(txt:String = ''):String
> > {
> > var data:ByteArray = Base64.decodeToByteArray(txt);
> > var pad:IPad = new PKCS5;
> > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > pad.setBlockSize(mode.getBlockSize());
> > mode.decrypt(data);
> > return Hex.toString(Hex.fromArray(data));
> > }
> > }
> > }
> > <?
> > class Crypt
> > {
> > var $key = NULL;
> > var $iv = NULL;
> > var $iv_size = NULL;
> > function Crypt()
> > {
> > $this->init();
> > }
> > function init($key = "")
> > {
> > $this->key = ($key != "") ? $key : "";
> > $this->algorithm = MCRYPT_DES;
> > $this->mode = MCRYPT_MODE_ECB;
> > $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
> > $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
> > }
> > function encrypt($data)
> > {
> > $size = mcrypt_get_block_size($this->algorithm, $this->mode);
> > $data = $this->pkcs5_pad($data, $size);
> > return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
> > $data, $this->mode, $this->iv));
> > }
> > function decrypt($data)
> > {
> > return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
> > $this->key, base64_decode($data), $this->mode, $this->iv)));
> > }
> > function pkcs5_pad($text, $blocksize)
> > {
> > $pad = $blocksize - (strlen($text) % $blocksize);
> > return $text . str_repeat(chr($pad), $pad);
> > }
> > function pkcs5_unpad($text)
> > {
> > $pad = ord($text{strlen($text)-1});
> > if ($pad > strlen($text)) return false;
> > if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
> > false;
> > return substr($text, 0, -1 * $pad);
> > }}
> > ?>
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"corbo... @yahoo.com" <corbo... @yahoo.com>
Date: Sat, 3 Jan 2009 18:47:49 -0800 (PST)
Local: Sat, Jan 3 2009 9:47 pm
Subject: Re: As3Crypto + PHP
the posting of my data service is here:
http://code.google.com/p/as3-to-
php-aes-dataservice/
it works with both flex and AIR appliactions
On Jan 3, 9:44 pm, "corbo... @yahoo.com" <corbo... @yahoo.com> wrote:
> I had problems making this work with PHP as well so i wrote a AES data-
> service to connect with PHP which uses javascript to encrypt and
> decrypt on the flex end. It works great and is all set up with
> functions on each end so it takes less then 3 lines of action-script
> and PHP to use it
> On Dec 27 2008, 6:59 pm, kleelof <klee... @yahoo.com> wrote:
> > Hello,
> > I've tried using this library, but I always get an error from the
> > base64 part that says constructors can only be declared public. If I
> > change it to public, I get another error.
> > I am using CS3. Can these files only be used in FLEX? I downloaded
> > both the source code, which I am attempting to use now, and the SWC
> > which I cannot figure out how to install since it did not come in an
> > installer packge.
> > take care,
> > lee
> > On Dec 16, 6:11 am, Jason <jason.fog... @gmail.com> wrote:
> > > Here it goes.
> > > I have spent alot of time on this and found no other way.
> > > No one else had examples so here is goes.
> > > package
> > > {
> > > import flash.display.Sprite;
> > > import flash.utils.ByteArray;
> > > import com.hurlant.crypto.symmetric.ICipher;
> > > import com.hurlant.crypto.symmetric.IVMode;
> > > import com.hurlant.crypto.symmetric.IMode;
> > > import com.hurlant.crypto.symmetric.NullPad;
> > > import com.hurlant.crypto.symmetric.PKCS5;
> > > import com.hurlant.crypto.symmetric.IPad;
> > > import com.hurlant.util.Base64;
> > > import com.hurlant.util.Hex;
> > > import com.hurlant.crypto.Crypto;
> > > public class CryptoCode extends Sprite
> > > {
> > > private var type:String='simple-des-ecb';
> > > private var key:ByteArray;
> > > public function CryptoCode()
> > > {
> > > init();
> > > }
> > > private function init():void
> > > {
> > > key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
> > > characters long
> > > trace(encrypt('TEST TEST'));
> > > trace(decrypt(encrypt('TEST TEST'));
> > > }
> > > private function encrypt(txt:String = ''):String
> > > {
> > > var data:ByteArray = Hex.toArray(Hex.fromString(txt));
> > > var pad:IPad = new PKCS5;
> > > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > > pad.setBlockSize(mode.getBlockSize());
> > > mode.encrypt(data);
> > > return Base64.encodeByteArray(data);
> > > }
> > > private function decrypt(txt:String = ''):String
> > > {
> > > var data:ByteArray = Base64.decodeToByteArray(txt);
> > > var pad:IPad = new PKCS5;
> > > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > > pad.setBlockSize(mode.getBlockSize());
> > > mode.decrypt(data);
> > > return Hex.toString(Hex.fromArray(data));
> > > }
> > > }
> > > }
> > > <?
> > > class Crypt
> > > {
> > > var $key = NULL;
> > > var $iv = NULL;
> > > var $iv_size = NULL;
> > > function Crypt()
> > > {
> > > $this->init();
> > > }
> > > function init($key = "")
> > > {
> > > $this->key = ($key != "") ? $key : "";
> > > $this->algorithm = MCRYPT_DES;
> > > $this->mode = MCRYPT_MODE_ECB;
> > > $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
> > > $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
> > > }
> > > function encrypt($data)
> > > {
> > > $size = mcrypt_get_block_size($this->algorithm, $this->mode);
> > > $data = $this->pkcs5_pad($data, $size);
> > > return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
> > > $data, $this->mode, $this->iv));
> > > }
> > > function decrypt($data)
> > > {
> > > return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
> > > $this->key, base64_decode($data), $this->mode, $this->iv)));
> > > }
> > > function pkcs5_pad($text, $blocksize)
> > > {
> > > $pad = $blocksize - (strlen($text) % $blocksize);
> > > return $text . str_repeat(chr($pad), $pad);
> > > }
> > > function pkcs5_unpad($text)
> > > {
> > > $pad = ord($text{strlen($text)-1});
> > > if ($pad > strlen($text)) return false;
> > > if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
> > > false;
> > > return substr($text, 0, -1 * $pad);
> > > }}
> > > ?>
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"corbo... @yahoo.com" <corbo... @yahoo.com>
Date: Sat, 3 Jan 2009 18:52:18 -0800 (PST)
Local: Sat, Jan 3 2009 9:52 pm
Subject: Re: As3Crypto + PHP
sorry that link was bad this is the right one:
http://code.google.com/p/as3-to-php-aes-dataservice/
On Jan 3, 9:47 pm, "corbo... @yahoo.com" <corbo... @yahoo.com> wrote:
> the posting of my data service is here:
http://code.google.com/p/as3-to-
> php-aes-dataservice/
> it works with both flex and AIR appliactions
> On Jan 3, 9:44 pm, "corbo... @yahoo.com" <corbo... @yahoo.com> wrote:
> > I had problems making this work with PHP as well so i wrote a AES data-
> > service to connect with PHP which uses javascript to encrypt and
> > decrypt on the flex end. It works great and is all set up with
> > functions on each end so it takes less then 3 lines of action-script
> > and PHP to use it
> > On Dec 27 2008, 6:59 pm, kleelof <klee... @yahoo.com> wrote:
> > > Hello,
> > > I've tried using this library, but I always get an error from the
> > > base64 part that says constructors can only be declared public. If I
> > > change it to public, I get another error.
> > > I am using CS3. Can these files only be used in FLEX? I downloaded
> > > both the source code, which I am attempting to use now, and the SWC
> > > which I cannot figure out how to install since it did not come in an
> > > installer packge.
> > > take care,
> > > lee
> > > On Dec 16, 6:11 am, Jason <jason.fog... @gmail.com> wrote:
> > > > Here it goes.
> > > > I have spent alot of time on this and found no other way.
> > > > No one else had examples so here is goes.
> > > > package
> > > > {
> > > > import flash.display.Sprite;
> > > > import flash.utils.ByteArray;
> > > > import com.hurlant.crypto.symmetric.ICipher;
> > > > import com.hurlant.crypto.symmetric.IVMode;
> > > > import com.hurlant.crypto.symmetric.IMode;
> > > > import com.hurlant.crypto.symmetric.NullPad;
> > > > import com.hurlant.crypto.symmetric.PKCS5;
> > > > import com.hurlant.crypto.symmetric.IPad;
> > > > import com.hurlant.util.Base64;
> > > > import com.hurlant.util.Hex;
> > > > import com.hurlant.crypto.Crypto;
> > > > public class CryptoCode extends Sprite
> > > > {
> > > > private var type:String='simple-des-ecb';
> > > > private var key:ByteArray;
> > > > public function CryptoCode()
> > > > {
> > > > init();
> > > > }
> > > > private function init():void
> > > > {
> > > > key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
> > > > characters long
> > > > trace(encrypt('TEST TEST'));
> > > > trace(decrypt(encrypt('TEST TEST'));
> > > > }
> > > > private function encrypt(txt:String = ''):String
> > > > {
> > > > var data:ByteArray = Hex.toArray(Hex.fromString(txt));
> > > > var pad:IPad = new PKCS5;
> > > > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > > > pad.setBlockSize(mode.getBlockSize());
> > > > mode.encrypt(data);
> > > > return Base64.encodeByteArray(data);
> > > > }
> > > > private function decrypt(txt:String = ''):String
> > > > {
> > > > var data:ByteArray = Base64.decodeToByteArray(txt);
> > > > var pad:IPad = new PKCS5;
> > > > var mode:ICipher = Crypto.getCipher(type, key, pad);
> > > > pad.setBlockSize(mode.getBlockSize());
> > > > mode.decrypt(data);
> > > > return Hex.toString(Hex.fromArray(data));
> > > > }
> > > > }
> > > > }
> > > > <?
> > > > class Crypt
> > > > {
> > > > var $key = NULL;
> > > > var $iv = NULL;
> > > > var $iv_size = NULL;
> > > > function Crypt()
> > > > {
> > > > $this->init();
> > > > }
> > > > function init($key = "")
> > > > {
> > > > $this->key = ($key != "") ? $key : "";
> > > > $this->algorithm = MCRYPT_DES;
> > > > $this->mode = MCRYPT_MODE_ECB;
> > > > $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
> > > > $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
> > > > }
> > > > function encrypt($data)
> > > > {
> > > > $size = mcrypt_get_block_size($this->algorithm, $this->mode);
> > > > $data = $this->pkcs5_pad($data, $size);
> > > > return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
> > > > $data, $this->mode, $this->iv));
> > > > }
> > > > function decrypt($data)
> > > > {
> > > > return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
> > > > $this->key, base64_decode($data), $this->mode, $this->iv)));
> > > > }
> > > > function pkcs5_pad($text, $blocksize)
> > > > {
> > > > $pad = $blocksize - (strlen($text) % $blocksize);
> > > > return $text . str_repeat(chr($pad), $pad);
> > > > }
> > > > function pkcs5_unpad($text)
> > > > {
> > > > $pad = ord($text{strlen($text)-1});
> > > > if ($pad > strlen($text)) return false;
> > > > if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
> > > > false;
> > > > return substr($text, 0, -1 * $pad);
> > > > }}
> > > > ?>
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Tim E <tim.... @gmail.com>
Date: Tue, 10 Feb 2009 02:31:50 -0800 (PST)
Local: Tues, Feb 10 2009 5:31 am
Subject: Re: As3Crypto + PHP
I want to do the same thing except with AES/Rijndael 256 encryption.
I use the AS2 crypto library: http://www.svendens.com/downloads/flashCrypt.zip
What does flash output? And what does PHP(mcrypt) expect?
For what i know actionscript create a Hex string, but php want an
bytearraystring or something?
I really need some help for this, there are not many resources where i
can find help.
On Dec 16 2008, 12:11 am, Jason <jason.fog... @gmail.com> wrote:
> Here it goes.
> I have spent alot of time on this and found no other way.
> No one else had examples so here is goes.
> package
> {
> import flash.display.Sprite;
> import flash.utils.ByteArray;
> import com.hurlant.crypto.symmetric.ICipher;
> import com.hurlant.crypto.symmetric.IVMode;
> import com.hurlant.crypto.symmetric.IMode;
> import com.hurlant.crypto.symmetric.NullPad;
> import com.hurlant.crypto.symmetric.PKCS5;
> import com.hurlant.crypto.symmetric.IPad;
> import com.hurlant.util.Base64;
> import com.hurlant.util.Hex;
> import com.hurlant.crypto.Crypto;
> public class CryptoCode extends Sprite
> {
> private var type:String='simple-des-ecb';
> private var key:ByteArray;
> public function CryptoCode()
> {
> init();
> }
> private function init():void
> {
> key = Hex.toArray(Hex.fromString('TESTTEST'));// can only be 8
> characters long
> trace(encrypt('TEST TEST'));
> trace(decrypt(encrypt('TEST TEST'));
> }
> private function encrypt(txt:String = ''):String
> {
> var data:ByteArray = Hex.toArray(Hex.fromString(txt));
> var pad:IPad = new PKCS5;
> var mode:ICipher = Crypto.getCipher(type, key, pad);
> pad.setBlockSize(mode.getBlockSize());
> mode.encrypt(data);
> return Base64.encodeByteArray(data);
> }
> private function decrypt(txt:String = ''):String
> {
> var data:ByteArray = Base64.decodeToByteArray(txt);
> var pad:IPad = new PKCS5;
> var mode:ICipher = Crypto.getCipher(type, key, pad);
> pad.setBlockSize(mode.getBlockSize());
> mode.decrypt(data);
> return Hex.toString(Hex.fromArray(data));
> }
> }
> }
> <?
> class Crypt
> {
> var $key = NULL;
> var $iv = NULL;
> var $iv_size = NULL;
> function Crypt()
> {
> $this->init();
> }
> function init($key = "")
> {
> $this->key = ($key != "") ? $key : "";
> $this->algorithm = MCRYPT_DES;
> $this->mode = MCRYPT_MODE_ECB;
> $this->iv_size = mcrypt_get_iv_size($this->algorithm, $this->mode);
> $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND);
> }
> function encrypt($data)
> {
> $size = mcrypt_get_block_size($this->algorithm, $this->mode);
> $data = $this->pkcs5_pad($data, $size);
> return base64_encode(mcrypt_encrypt($this->algorithm, $this->key,
> $data, $this->mode, $this->iv));
> }
> function decrypt($data)
> {
> return $this->pkcs5_unpad(rtrim(mcrypt_decrypt($this->algorithm,
> $this->key, base64_decode($data), $this->mode, $this->iv)));
> }
> function pkcs5_pad($text, $blocksize)
> {
> $pad = $blocksize - (strlen($text) % $blocksize);
> return $text . str_repeat(chr($pad), $pad);
> }
> function pkcs5_unpad($text)
> {
> $pad = ord($text{strlen($text)-1});
> if ($pad > strlen($text)) return false;
> if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return
> false;
> return substr($text, 0, -1 * $pad);
> }}
> ?>
You must
Sign in before you can post messages.
You do not have the permission required to post.