SHA-512 library for PHP
If you are using PHP >= 5.3, the function openssl_digest
should do the trick :
echo openssl_digest('glop', 'sha512');
gives me this output (splitted in two lines to get better readibility) :416b1861951170e1f6eb6543b0dd3d4f1994ce8da7cd82061513d3ddd1dd81111
f4ada5caf6421f1d17425c6f29bdb4a95cf84df9eda4164f5a762acbb490a68
(And you can use openssl_get_md_methods
to get the list of available digest methods)
And with PHP 5.1 or 5.2, you have the hash
function :
echo hash('sha512', 'glop');
gives me the same output (splitted, too) :416b1861951170e1f6eb6543b0dd3d4f1994ce8da7cd82061513d3ddd1dd81111
f4ada5caf6421f1d17425c6f29bdb4a95cf84df9eda4164f5a762acbb490a68
And, here, to know the list of available digest methods, you can use hash_algos
SHA512 hashes differ on android, php and javascript
SHA1 is not made for security, don't use it for this.
Grab any implementation of BCrypt and do security right.
As for the different hashes: Most likely an encoding issue related to Strings.
Similar sha512 of php for android password login
Can you try the code below. Did some minor changes in your code.
String resultString = "";
try {
byte[] buffer = password.getBytes();
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(buffer);
byte[] digest = md.digest();
for(int i = 0 ; i < digest.length ; i++) {
int b = digest[i] & 0xff;
if(Integer.toHexString(b).length() == 1)
resultString = resultString + "0";
resultString = resultString + Integer.toHexString(b);
}
} catch(NoSuchAlgorithmException e) {
e.printStackTrace();
}
SHA512 with salt for iOS
Your code has two problems:
Your ObjC code appears to be calculating a SHA512 HMAC and your PHP code is calculating a SHA512 hash which are 2 different beasts. As far as I know [which is not far] the corresponding PHP code should be something like:
hash_hmac('SHA512', '123', '123' );
The output for the above is still much longer that the ObjC code, ie:
Which is 128 characters [512 bits] long and ostensibly the expected length from SHA512 function.0634fd04380bbaf5069c8c46a74c7d21df7414888d980c27a16d5e262cb8c9059139c212d0926000faf026e483904cefae2f5e9d9bd5f51fbc2ac4c4de518115
Java SHA512 digest output differs from PHP script
The first hash should be the same on the server and in Java. But then in the loop what gets appended to the digest is password{salt}
in the PHP code, but only {salt}
in the Java code.
Correctly using crypt() with SHA512 in PHP
The main reason to run the algorithm for a certain amount of rounds is simply to slow it down to make brute forcing attacks uninteresting. For that 5000 iterations are enough even for modern hardware. You could as well use 100000 but then your server admin would probably want to have a word with you :-)
rounds=5000 is the default for SHA-512. The minimum is 1000 and the maximum very high.
Related Topics
Changes to Upload_Max_Filesize in Ubuntu PHP.Ini Will Not Take Effect
How to Use a PHP Class from Another File
Download the Contents of a Url in PHP Even If It Returns a 404
Include Just Files in Scandir Array
Determining If a File Exists in Laravel 5
How to Determine the Length (In Pixels) of a String Being Rendered on a Web Page
How to Wrap Text Using Imagick in PHP So That It Is Drawn as Multiline Text
How to Change the Default Netbeans 7 Project Directory
PHP - What's the Benefit of Unsetting Variables
Difference Between Buffered and Unbuffered Queries
Imagemagick Brew Installation with PHP Module in MAC Os X
Number in the Top-Level Domain
Convert Multidimensional Objects to Array
How to Add Custom Fields to Woocommerce Registration Form
Php: How to Read a File Live That Is Constantly Being Written To