This .sha512 file is encrypting key for a zip file and inside this .sha512 file, there is a hash key and the name of the zip using which this was created from.
I wanted to know if sha512sum -c
command runs checksum on the zip file and then matches the value inside of the .sha512 file or there is another function to the command.
I had this command inside a if statement, and if checksum values match then it would print Checksum matches or else prints checksum values do not match.
Thanks for the help.
Im newbee in terms of encryption algho im trying to create SHA-512 to convert this variable data into SHA-512 so i can pass it in server in my project any help will be appreciated.
if (pojo.getAmount() != null && !pojo.getAmount().equals("")) { //Data variables needs to convert in SHA-512 hsString = merchantID + "" + "" + req_id + "" + ip_address + "" + notication_url + "" + package_name + "" + firstname + "" + lastname + "" + middlename + "" + address1 + "" + address2 + "" + city + "" + state + "" + country + "" + zip + "" + email + "" + phone + "" + client_ip + "" + "" + cost + "" + currency + "" + secur3d + "" + merchantKey; //base64string one of the transaction parameters base64_enconded = Base64.encodeToString(hsString.getBytes(),Base64.DEFAULT);
I have my code down to the essentials for testing access, but am receiving the good old error(403) from the server, I have verified for double-sure I am using the correct API Key/Secret pair. My Code (C# via Unity 3D) is as follows:
using System.Collections;using System.Collections.Generic;using UnityEngine;using System;using System.Security.Cryptography;using System.IO;using System.Text;using System.Net;public class PolonScript : MonoBehaviour{ public TextMesh OutputText; const string _apiKey = "---apiKey---"; const string _apiSecret = "---apiSecret---"; void Start() { string nonce = DateTime.Now.ToString ("HHmmss"); const string WEBSERVICE_URL = "https://poloniex.com/tradingApi"; try { var webRequest = System.Net.WebRequest.Create (WEBSERVICE_URL); if (webRequest != null) { webRequest.Method = "POST"; //webRequest.Timeout = 12000; webRequest.ContentType = "application/x-www-form-urlencoded"; byte[] dataStream = Encoding.UTF8.GetBytes("command=returnBalances&nonce=" + nonce); webRequest.Headers.Add("Key", _apiKey); webRequest.Headers.Add("Sign", genHMAC (dataStream)); Stream newStream = webRequest.GetRequestStream(); newStream.Write(dataStream, 0, dataStream.Length); newStream.Close(); using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream()) { using (System.IO.StreamReader sr = new System.IO.StreamReader(s)) { var jsonResponse = sr.ReadToEnd(); OutputText.text = jsonResponse.ToString(); } } } } catch (WebException ex) { OutputText.text = ex.ToString(); } } //end-of-start() private string genHMAC(byte[] dataStreamInput) { byte [] APISecret_Bytes = System.Text.Encoding.UTF8.GetBytes(_apiSecret); HMACSHA512 hmac = new HMACSHA512(APISecret_Bytes); var signBytes = hmac.ComputeHash(dataStreamInput); string HexDecString = string.Empty; for (int i = 0; i < signBytes.Length; i++) { HexDecString += signBytes[i].ToString("X2"); } return HexDecString; }}
So why am I receiving the (403) Forbidden using accurate credentials?
I tried this to see the reason:
catch (WebException ex) { OutputText.text = ex.Response.Headers.ToString ();}
and receive the following
//Date: Sat, 14 Apr 2018 15:34:56 GMT//Content-Type: application/json//Transfer-Encoding: chunked//Connection: keep-alive//Set-Cookie: __cfduid=dd1b32592915674669120afbf8181141b1523720096; expires=Sun, 14-Apr-19 15:34:56 GMT; path=/; domain=.poloniex.com; HttpOnly//Cache-Control: private//Expect-CT: max-age=604800, report-uri="https://report-//uri.cloudflare.com/cdn-cgi/beacon/expect-ct"//Server: cloudflare//CF-RAY: 40b73d4b8c98552e-ORD
I already have a database which contains a table named User, this table contains a table salt, password etc...
my database was created by symfony(ORM+FOSUserBundle)
he use sha512.
I am trying to get a salt and a password , and store them into the database from desktop java application, so I tried this Class:
import com.google.common.io.BaseEncoding;import org.slf4j.Logger;import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import com.google.common.primitives.Bytes;import org.slf4j.LoggerFactory;public class SHA512 { private static final Logger log = LoggerFactory.getLogger(SHA512.class); private static final String ALGORITHM = "SHA-512"; private static final int ITERATIONS = 5000; private static final int SALT_SIZE = 43; /** * Private constructor. */ private SHA512() { } public static void main(String[] args) { String password = "0000"; try { byte[] salt = generateSalt(); log.info("Password {}. hash algorithm {}, iterations {}, salt {}", password, ALGORITHM, ITERATIONS, BaseEncoding.base64().encode(salt)); byte[] hash = calculateHash(password, salt); boolean correct = verifyPassword(hash, password, salt); log.info("Entered password is correct: {}", correct); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { log.error(ex.getMessage(), ex); } } private static byte[] generateSalt() { SecureRandom random = new SecureRandom(); byte[] salt = new byte[SALT_SIZE]; random.nextBytes(salt); return salt; } private static byte[] calculateHash(String password, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance(ALGORITHM); md.reset(); md.update(Bytes.concat(password.getBytes("UTF-8"), salt)); byte[] hash = md.digest(); for (int i = 0; i < ITERATIONS; i++) { md.reset(); hash = md.digest(hash); } return hash; } private static boolean verifyPassword(byte[] originalHash, String password, byte[] salt) throws NoSuchAlgorithmException, UnsupportedEncodingException { byte[] comparisonHash = calculateHash(password, salt); log.info("hash 1: {}", BaseEncoding.base64().encode(originalHash)); log.info("hash 2: {}", BaseEncoding.base64().encode(comparisonHash)); return comparePasswords(originalHash, comparisonHash); } /** * Compares the two byte arrays in length-constant time using XOR. * * @param originalHash The original password hash * @param comparisonHash The comparison password hash * @return True if both match, false otherwise */ private static boolean comparePasswords(byte[] originalHash, byte[] comparisonHash) { int diff = originalHash.length ^ comparisonHash.length; for (int i = 0; i < originalHash.length && i < comparisonHash.length; i++) { diff |= originalHash[i] ^ comparisonHash[i]; } return diff == 0; }}
I need a salt with lenght 43, But BaseEncoding.base64().encode(salt)
output salt with lenght equal 60.I modified the SALT_SIZE to 30 and BaseEncoding.base64().encode(salt)
output a salt with length equal to 40 but, when I add a user with that salt and with the hash generated, I can't Login with this user from my web application(already said that FOSUserBundle controls authentication and encode/decode algorithm)
I have multiple zip files that I would like to get checked if they were not compromised while getting transfered, and if the checksum values match then I need to unzip the folder.
I am able to do this for one zip file, but I want dynamic checking, so I do not have to replace the zip file name each time to run the check.
Here is what I have until now:
if [[ $(sha512sum file.zip | cut -d " " -f 1) -ne $(cat file.sha512) ]]; then log "error" "Checksum values do not match" exit -1; else log "info" "Checksum values match" unzip file.zip
So I have other zip files called file1, file2, and the .sha512 name also tends to be of the same name as of their corresponding zip file.
Thanks in advance.
Please note that by viewing our site you agree to our use of cookies (see Privacy for details). You will only see this message once.