How to sha256 a value in PHP
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
How to sha256 a value in PHP
I have got a variable in PHP which has to be sha256'd. How it can be done?
Normally, in case of member registration we can do it when we get the values of the form in javascript. but how can we deal with this situation???
Normally, in case of member registration we can do it when we get the values of the form in javascript. but how can we deal with this situation???
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
$hashed_string = SHA256::hash($string_to_hash);- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Is there a class been written to sha256 a value in PHP??? I dont know about this. I thought that function is just available in Javascript alone.
Its good really!!!
Is it possible to see the class definition???
It appears like I have to include the class? It does not recognize the existance of such a class, sha256. How do I do that???
Its good really!!!
Is it possible to see the class definition???
It appears like I have to include the class? It does not recognize the existance of such a class, sha256. How do I do that???
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Yes, there is a class. I wrote it. Roja has tested it on many platforms, and I know I've seen several sites around the net linking to it.raghavan20 wrote:Is there a class been written to sha256 a value in PHP???
It basically was until I wrote mineraghavan20 wrote:I thought that function is just available in Javascript alone.
Code Snippets: Security: SHA256 Hashing Algorithm Updated v1.1.0raghavan20 wrote:Is it possible to see the class definition???
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Its really good job
Thanks for supporting open source with your contributions.
A suggestion, you can give all those three php files in a zip file. It was a nightmare for me to copy them which are under the PHP tags. I had to click on QUOTE link to see the code in textarea and I copied them as new php files.
I downloaded those three files and included test_sha256.php in my admin page. but it displays a few messages. do I have to track the code to remove all of them? It also stops the code in my admin page from executing. how do I counter this???
Thanks for supporting open source with your contributions.
A suggestion, you can give all those three php files in a zip file. It was a nightmare for me to copy them which are under the PHP tags. I had to click on QUOTE link to see the code in textarea and I copied them as new php files.
I downloaded those three files and included test_sha256.php in my admin page. but it displays a few messages. do I have to track the code to remove all of them? It also stops the code in my admin page from executing. how do I counter this???
Code: Select all
unning testSHA256::test1()
Testing 'abc'
array(1)::
string(64)::
61626380 00000000 00000000 00000000
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000018
end array;
array(8)::
string(4)::
6A09E667
string(4)::
BB67AE85
string(4)::
3C6EF372
string(4)::
A54FF53A
string(4)::
510E527F
string(4)::
9B05688C
string(4)::
1F83D9AB
string(4)::
5BE0CD19
end array;
processing took 0.00023100000000001 seconds.
Testing 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
array(2)::
string(64)::
61626364 62636465 63646566 64656667
65666768 66676869 6768696A 68696A6B
696A6B6C 6A6B6C6D 6B6C6D6E 6C6D6E6F
6D6E6F70 6E6F7071 80000000 00000000
string(64)::
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000
00000000 00000000 00000000 000001C0
end array;
array(8)::
string(4)::
6A09E667
string(4)::
BB67AE85
string(4)::
3C6EF372
string(4)::
A54FF53A
string(4)::
510E527F
string(4)::
9B05688C
string(4)::
1F83D9AB
string(4)::
5BE0CD19
end array;
processing took 0.000143 seconds.
running testSHA256::test2()
Testing 'abc'
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
processing took 0.300786 seconds.
Testing 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'
248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
processing took 0.471874 seconds.
running testSHA256::testSum()
55
running testSHA256::testSpeedHash(array ( 0 => 10, ))
Testing ''
Start time: 2005-08-28 17:09:53
estimated time to perform test: 1.51689 seconds for 10 iterations.
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' == 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' PASSED
processing took 0.0865916 seconds.
Testing 'abc'
Start time: 2005-08-28 17:09:54
estimated time to perform test: 0.79443 seconds for 10 iterations.
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' == 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' PASSED
processing took 0.0824555 seconds.
Testing 'message digest'
Start time: 2005-08-28 17:09:55
estimated time to perform test: 0.792 seconds for 10 iterations.- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
yeah. I had planned to put them up in a zip & tar.gz at some point, along with a live example page and tutorials on its use, but I've been busy 
You don't require test_sha256, it's merely to help debug (1), so you can see both the amount of computations involved (2), and see if your copy is working correctly (3). It appears to be working as expected.
The only requirements are the first two files. Even those can be paired down to a streamlined version with just the SHA256 class, no abstract ancestor.
You don't require test_sha256, it's merely to help debug (1), so you can see both the amount of computations involved (2), and see if your copy is working correctly (3). It appears to be working as expected.
The only requirements are the first two files. Even those can be paired down to a streamlined version with just the SHA256 class, no abstract ancestor.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Code: Select all
$hashed_string = SHA256::hash($string_to_hash);Code: Select all
MyHash extends SHA256 {}
$hashed_string = MyHash::hash($string_to_hash);- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US