关于hash_hmac("MD5", "aa=11&bb=2&c=lai") 1C

图片说明

大家好,我是开发java的,最近遇到一个和php相关的问题,想和大家请教一下

hash_hmac(“MD5”, "a=1&b=data&c=2","私钥")

php的这个函数内部是怎么实现的,我目前需要用java做一个签名函数,和php的hash_hmac函数功能一致,网上搜索的都使用不了,所以想知道这个函数底层源码是怎么实现的,这样我就可以用java实现了

搜索到一个阿里的技术文档,内容如下,但是无法使用:
public static byte[] encryptHMAC(String data, String secret) throws Exception {
byte[] bytes = null;
try {
SecretKey secretKey = new SecretKeySpec(secret.getBytes(Constants.ENCODE_UTF8), "HmacMD5");
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
bytes = mac.doFinal(data.getBytes(Constants.ENCODE_UTF8));
} catch (Exception gse) {
throw new IOException(gse.toString());
}
return bytes;
}

public static String byte2hex(byte[] bytes) {
    StringBuilder sign = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        String hex = Integer.toHexString(bytes[i] & 0xFF);
        if (hex.length() == 1) {
            sign.append("0");
        }
        sign.append(hex.toUpperCase());
    }

    System.out.println(sign.toString().toLowerCase());
    return sign.toString().toLowerCase();
}

1个回答

请各位php的开发者,说一下这个函数的 hash_hmac(“MD5”, "a=1&b=data&c=2","私钥") 底层实现原理

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于hash_hmac("MD5", "aa=11&bb=2&c=lai")

![图片说明](https://img-ask.csdn.net/upload/201708/20/1503214664_744015.png) 大家好,我是开发java的,最近遇到一个和php相关的问题,想和大家请教一下 hash_hmac(“MD5”, "a=1&b=data&c=2","私钥") php的这个函数内部是怎么实现的,我目前需要用java做一个签名函数,和php的hash_hmac函数功能一致,网上搜索的都使用不了,所以想知道这个函数底层源码是怎么实现的,这样我就可以用java实现了 搜索到一个阿里的技术文档,内容如下,但是无法使用: public static byte[] encryptHMAC(String data, String secret) throws Exception { byte[] bytes = null; try { SecretKey secretKey = new SecretKeySpec(secret.getBytes(Constants.ENCODE_UTF8), "HmacMD5"); Mac mac = Mac.getInstance(secretKey.getAlgorithm()); mac.init(secretKey); bytes = mac.doFinal(data.getBytes(Constants.ENCODE_UTF8)); } catch (Exception gse) { throw new IOException(gse.toString()); } return bytes; } public static String byte2hex(byte[] bytes) { StringBuilder sign = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); } sign.append(hex.toUpperCase()); } System.out.println(sign.toString().toLowerCase()); return sign.toString().toLowerCase(); }

如何在节点js中使用hash_hmac函数

<div class="post-text" itemprop="text"> <p>Recently I have used same code on PHP and it's working fine but when I tried Node Js, it's not working for me. Please check once: </p> <p>PHP </p> <pre><code>$signature = $ACCID . "POST" . strtolower(urlencode($url)).$requestContentBase64String; $hmacsignature = base64_encode(hash_hmac("sha256", $signature, base64_decode($APIKey), true)); </code></pre> <p>NODE CODE : </p> <pre><code>var signature = ACCID+"POST"+encodeURI(url).toLowerCase()+requestContentBase64String; var hmacsignature = base64.encode(crypto.createHmac('sha256', APIKey).update(signature).digest('base64')) </code></pre> <p>Please check what's wrong in this code. </p> </div>

SHA1秘密编码,等效于PHP hash_hmac

<div class="post-text" itemprop="text"> <p>I have the following PHP function</p> <pre><code>public function encodePassword($raw, $salt) { return hash_hmac('sha1', $raw . $salt, $this-&gt;secret); } </code></pre> <p>which I need to translate to Go. I found the following example, but it doesn't involve secret key. <a href="https://gobyexample.com/sha1-hashes" rel="nofollow noreferrer">https://gobyexample.com/sha1-hashes</a></p> <p>How can I create a function in Go, that produces exactly same result as PHP's hash_hmac?</p> <blockquote> <p>Update: After Leo's answer, found this resource with hmac examples in many languages: <a href="https://github.com/danharper/hmac-examples" rel="nofollow noreferrer">https://github.com/danharper/hmac-examples</a>. Can be useful to somebody.</p> </blockquote> </div>

PHP中的HMAC md5加密/解密[重复]

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/15194663/encrypt-and-decrypt-md5" dir="ltr">encrypt and decrypt md5</a> <span class="question-originals-answer-count"> 6 answers </span> </li> </ul> </div> <p>I have the php code for making HMAC md5 encryption</p> <pre><code>$input = 'foo'; $output = hash_hmac('md5', $input, $secretKey); </code></pre> <p>After making the hash,is there anyway I could get the $input back to text form.</p> </div>

如何在PHP上使用hash_hmac()和“SHA256withRSA”?

<div class="post-text" itemprop="text"> <p>I'm trying to get PayPal Webhooks to work with my PHP app. The problem is the hashing algorithm they send via headers, that i must use to verify if the request is valid. </p> <p>When I try to use it, I get this error:</p> <pre><code>hash_hmac(): Unknown hashing algorithm: SHA256withRSA </code></pre> <p>I have tried hash_hmac using just the "sha256" algo and it worked, so I think the problem must be with the one they want me to use.</p> <p>Here is the code I use to process the Webhook:</p> <pre><code>$headers = apache_request_headers(); $body = @file_get_contents('php://input'); $json = json_decode($body); // Concatanate the reqired strings values $sigString = $headers['PAYPAL-TRANSMISSION-ID'].'|'.$headers['PAYPAL-TRANSMISSION-TIME'].'|'.$json-&gt;id.'|'.crc32($body); // Get the certificate file and read the key $pub_key = openssl_pkey_get_public(file_get_contents($headers['PAYPAL-CERT-URL'])); $keyData = openssl_pkey_get_details($pub_key); // check signature if ($headers['PAYPAL-TRANSMISSION-SIG'] != hash_hmac($headers['PAYPAL-AUTH-ALGO'],$sigString,$keyData['key'])) { //invalid } </code></pre> </div>

如何通过PKCS5_PBKDF2_HMAC和hash_hmac在C和php中获得相同的输出

<div class="post-text" itemprop="text"> <p>I'm trying to duplicate a hashing function in C to be used on an existing database of hashes and salts. However once I reduced how PHP gets a sha256 hash and how c gets one, I can't get the same hashes. </p> <p>I have looked though quite a few methods of getting the same hashes in C, but I can't quite figure out what's wrong the C code. The C code works, but the output is not the same.</p> <p>Here is the base of my PHP code, it takes password and uses a single space as a salt, the rest of the code is just to visualize and see the output:</p> <pre><code>&lt;?php $salt = ' '; $password = 'password'; $temp1 = hash_hmac('sha256', $salt, $password, true); echo "====================== &lt;br&gt;"; echo "password [${password}] &lt;br&gt;"; echo "salt [${salt}] &lt;br&gt;"; echo "====================== &lt;br&gt;"; echo gettype($temp1) . " &lt;br&gt;"; echo "each char as dechex(ord(x)) &lt;br&gt;"; for ($i = 0; $i &lt; strlen($temp1); ++$i) { $x = dechex(ord($temp1[$i])); echo "[$x] "; } echo "------------------------- &lt;br&gt;"; echo "base64_encode &lt;br&gt;"; echo base64_encode($temp1)." &lt;br&gt;"; ?&gt; </code></pre> <p>and the output</p> <pre><code>====================== password [password] salt [ ] ====================== string each char as dechex(ord(x)) [52] [33] [c] [6b] [2f] [b6] [22] [cd] [bb] [73] [93] [c2] [5c] [be] [6c] [f4] [d3] [a6] [26] [cc] [ef] [aa] [9] [5e] [e0] [93] [33] [8] [83] [8d] [9] [63] ------------------------- base64_encode UjMMay+2Is27c5PCXL5s9NOmJszvqgle4JMzCIONCWM= </code></pre> <p>The C I'm using, this is the simplest of examples I could find. I am only looking to get the same hash output. It does not have to use this method. I also included the base64 include function I'm using just in case:</p> <pre><code> #include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;openssl/evp.h&gt; #include &lt;openssl/sha.h&gt; #include &lt;openssl/pem.h&gt; #include &lt;openssl/hmac.h&gt; #define PBKDF2_DIGEST_LENGTH SHA256_DIGEST_LENGTH #define PBKDF2_SALT_PREFIX "" #define PBKDF2_SALT_PREFIX_LENGTH strlen(PBKDF2_SALT_PREFIX) #define PBKDF2_PRF_ALGORITHM_OLD EVP_sha512() #define PBKDF2_DIGEST_LENGTH_OLD SHA512_DIGEST_LENGTH #define PBKDF2_SALT_LENGTH 32 #define PBKDF2_RESULT_LENGTH PBKDF2_SALT_PREFIX_LENGTH + (2 * PBKDF2_DIGEST_LENGTH) + PBKDF2_SALT_LENGTH + 2 #define PBKDF2_ROUNDS 1000 #define PBKDF2_PRF_ALGORITHM EVP_sha256() char *base64encode (const void *b64_encode_this, int encode_this_many_bytes){ BIO *b64_bio, *mem_bio; //Declares two OpenSSL BIOs: a base64 filter and a memory BIO. BUF_MEM *mem_bio_mem_ptr; //Pointer to a "memory BIO" structure holding our base64 data. b64_bio = BIO_new(BIO_f_base64()); //Initialize our base64 filter BIO. mem_bio = BIO_new(BIO_s_mem()); //Initialize our memory sink BIO. BIO_push(b64_bio, mem_bio); //Link the BIOs by creating a filter-sink BIO chain. BIO_set_flags(b64_bio, BIO_FLAGS_BASE64_NO_NL); //No newlines every 64 characters or less. BIO_write(b64_bio, b64_encode_this, encode_this_many_bytes); //Records base64 encoded data. BIO_flush(b64_bio); //Flush data. Necessary for b64 encoding, because of pad characters. BIO_get_mem_ptr(mem_bio, &amp;mem_bio_mem_ptr); //Store address of mem_bio's memory structure. BIO_set_close(mem_bio, BIO_NOCLOSE); //Permit access to mem_ptr after BIOs are destroyed. BIO_free_all(b64_bio); //Destroys all BIOs in chain, starting with b64 (i.e. the 1st one). BUF_MEM_grow(mem_bio_mem_ptr, (*mem_bio_mem_ptr).length + 1); //Makes space for end null. (*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0'; //Adds null-terminator to tail. return (*mem_bio_mem_ptr).data; //Returns base-64 encoded data. (See: "buf_mem_st" struct). } int main(void) { static unsigned char hb[PBKDF2_DIGEST_LENGTH]; static unsigned char hashBlock[PBKDF2_DIGEST_LENGTH]; char *password = "password"; char *salt = " "; int passes = 1; PKCS5_PBKDF2_HMAC(password, strlen(password), salt, strlen(salt) , passes, PBKDF2_PRF_ALGORITHM, PBKDF2_DIGEST_LENGTH, hb); unsigned int i = 0; printf("printf hex "); while(i&lt;32) { printf("[%x] ", hb[i]); ++i; } printf(" "); printf("base-64 encode "); printf("%s ", base64encode(hb, 32)); return 0; } </code></pre> <p>The output that C produces, basically to visualize the output:</p> <pre><code> ./pbkdf2_hack printf hex [f8] [8b] [fe] [58] [64] [f8] [a] [ef] [c0] [da] [b2] [97] [42] [ce] [b3] [83] [67] [85] [a5] [f2] [c8] [94] [7b] [2d] [82] [5d] [8a] [a5] [c0] [46] [9a] [24] base-64 encode +Iv+WGT4Cu/A2rKXQs6zg2eFpfLIlHstgl2KpcBGmiQ= </code></pre> <p>Compiling, in case something needs to be different here:</p> <pre><code>gcc pbkdf2_example.c -lcrypto -o pbkdf2_example </code></pre> </div>

python爬取酷狗音乐返回值不正常

程序中链接返回值与浏览器返回值不一样 链接如下 https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback=jQuery191044011229047114075_1566198263706&hash=2398DDFC7C7420AB22A77DFEAE4CA551&album_id=1966068&dfid=1afQI30nxtgd0PXOun1bVc82&mid=2ccec311dd30b13705a140e6b7710e64&platid=4&_=1566198263708 浏览器中返回 jQuery191044011229047114075_1566198263706({"status":1,"err_code":0,"data":{"hash":"2398DDFC7C7420AB22A77DFEAE4CA551","timelength":215000,"filesize":8608960,"audio_name":"\u5468\u6770\u4f26 - \u544a\u767d\u6c14\u7403","have_album":1,"album_name":"\u5468\u6770\u4f26\u7684\u5e8a\u8fb9\u6545\u4e8b","album_id":"1645030","img":"http:\/\/imge.kugou.com\/stdmusic\/20160623\/20160623233610830051.jpg","have_mv":1,"video_id":"589001","author_name":"\u5468\u6770\u4f26","song_name":"","lyrics":"","author_id":"3520","privilege":0,"privilege2":"0","play_url":"","authors":[{"author_id":"3520","sizable_avatar":"http:\/\/singerimg.kugou.com\/uploadpic\/softhead\/{size}\/20180515\/20180515002522714.jpg","is_publish":"1","author_name":"\u5468\u6770\u4f26","avatar":"http:\/\/singerimg.kugou.com\/uploadpic\/softhead\/400\/20180515\/20180515002522714.jpg"}],"bitrate":320,"audio_id":"22084042"}}); requests.get(url) 程序返回结果为 'jQuery191044011229047114075_1566198263706({"status":0,"err_code":30020,"data":{"SSA-CODE":"gz_event_78fdc6448481401404133bcd88b001b1","SSA-HMID":"2ccec311dd30b13705a140e6b7710e64"}});' 怎么办?请大神解决 初步判断是网络原因,不网络不一样

php hash_hmac到c# - webresponse“NONCE_NOT_PROVIDED”

<div class="post-text" itemprop="text"> <p>I try to convert a php-code to c#</p> <p>php</p> <pre><code>$apikey='xxx'; $apisecretkey='yyy'; $nonce=time(); $uri='https://website.com/api/getsomething?apikey='.$apikey.'&amp;nonce='.$nonce; $sign=hash_hmac('sha512',$uri,$apisecretkey); $resource = curl_init($uri); curl_setopt($resource, CURLOPT_HTTPHEADER, array('apisign:'.$sign)); $execResult = curl_exec($resource); $obj = ($execResult); </code></pre> <p>and here my C#</p> <pre><code>WebRequest _WebRequest; WebResponse _WebResponse; string apikey = "xxx"; string apisecret = "yyy"; string nonce = ((int)(DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds).ToString(); string uri = $"https://website.com/api/getsomething?apikey={apikey}nonce={nonce}"; string _Hash_hmac = Hash_hmac(uri, apisecret); _WebRequest = WebRequest.Create(uri); _WebRequest.Headers["apisign"] = _Hash_hmac; _WebResponse = _WebRequest.GetResponse(); </code></pre> <p>The Code for Hash-hmac I use this <a href="https://stackoverflow.com/questions/12804231/c-sharp-equivalent-to-hash-hmac-in-php">C# equivalent to hash_hmac in PHP</a></p> <p>The Webresponse is always <em>"NONCE_NOT_PROVIDED"</em></p> <p>I checked the outcome from the hash_hmac with the one in php - they are the same. And also try string ToUpper and ToLower.</p> <p>What I am doing wrong?</p> </div>

将PHP中的hash_hmac转换为rails等效项

<div class="post-text" itemprop="text"> <p>I want to convert below PHP hash-code to equivalent ruby or rails code. </p> <pre><code>$publicHash = '3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348'; $privateHash = 'e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e'; $content = json_encode( array( 'test' =&gt; 'content' ) ); $hash = hash_hmac('sha256', $content, $privateHash); </code></pre> <p>$content is request params hash. </p> <p>I converted in ROR using, </p> <pre><code>public_hash = '3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348' private_hash = 'e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e' content = JSON::encode( paramsString ) hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), private_hash, content) </code></pre> <p>But no luck. Anything I am missing?</p> </div>

从hmac函数中得不到输出

<div class="post-text" itemprop="text"> <p>I want to use hmac to authenticate a user by email The hmac will be stored in the database along with the userid.</p> <ul> <li>Do I also need to store the <code>$payload</code> for decryption as well?</li> </ul> <p>Am I doing it right? </p> <p>I don't get any string in the url querystring?</p> <p>This is my testpage with the following</p> <pre><code>$secret = "dfjhglkhniuh65645"; $payload= "234|somedata"; $hmac = hash_hmac("sha2", $payload, $secret, true); //$hmac = base64_encode($hmac); if (! function_exists("hash_hmac")) { echo "hmac function does not exist"; } $uri="test.php?hash=$hmac"; if(!isset($_GET['hash'])){ header('location: ' . $uri); exit(); } echo "testpage&lt;br&gt;&lt;br&gt;"; if(isset($_GET['hash']) &amp;&amp; !empty($_GET['hash'])) { $sig = $_GET['hash']; $expected_sig = hash_hmac("sha2", $payload, $secret, true); if($expected_sig === $sig)echo "verification succeeded"; } </code></pre> </div>

生成用户唯一的hmac密钥以进行密码散列

<div class="post-text" itemprop="text"> <p>For my website's password hashing I wrote the following function:</p> <pre><code>public function hash($user) { $user_key = hash_hmac('sha512', $user['id'].$user['email'], $this-&gt;site_key); $password = hash_hmac('sha512', $user['password'], $user_key); } </code></pre> <p>I generate user unique keys to use for the final password hashing. Because this key is hashed with sha512 it should give enough security based on what I read on wikipedia: </p> <blockquote> <p>The cryptographic strength of the HMAC depends upon the cryptographic strength of the underlying hash function, the size of its hash output length in bits and on the size and quality of the cryptographic key.</p> </blockquote> <p>I have not seen this way if hashing passwords before and was wondering if it is good enough?</p> <p><strong>Extra</strong>: I have not used a salt because I <em>think</em> hmac appends the provided key to the data (like a salt), is this right?</p> </div>

C#中的原始HMAC-SHA1 - hmac_hash()PHP等效

<div class="post-text" itemprop="text"> <p>I am attempting to integrate Desk.com's Multipass SSO into my website, and am having trouble generating the correct HMAC-SHA1 signature (so say the error logs). Here are the directions from Desk.com's website:</p> <ol> <li>Build a SHA1 HMAC using your multipass API key and your finished multipass token.</li> <li>Base64 encode the resulting HMAC.</li> </ol> <p>According to the logs, my multipass token appears to be correct. First, the code in PHP that works perfectly:</p> <pre><code>// Build an HMAC-SHA1 signature using the multipass string and your API key $signature = hash_hmac("sha1", $multipass, $api_key, true); // Base64 encode the signature $signature = base64_encode($signature); </code></pre> <p>^ note that hash_hmac's 'true' value is outputting information in raw binary - I'm not sure if this is the case in my C# code</p> <p>Next, my C# code that is <em>not</em> working correctly:</p> <pre><code>protected string getSignature(string multipass) { string api_key = "my_key_goes_here"; HMACSHA1 hmac = new HMACSHA1(Encoding.ASCII.GetBytes(api_key)); hmac.Initialize(); byte[] buffer = Encoding.ASCII.GetBytes(multipass); string signature = BitConverter.ToString(hmac.ComputeHash(buffer)).Replace("-", "").ToLower(); return Convert.ToBase64String(Encoding.ASCII.GetBytes(signature)); } </code></pre> <p>This is the result of (literally) hours of searching and trying multiple different ways. I would be very grateful if I could get this figured out. </p> <p>If you need a reference, check out this page by Desk.com: <a href="http://dev.desk.com/docs/portal/multipass" rel="nofollow">http://dev.desk.com/docs/portal/multipass</a>. It has code examples and outlines the instructions for completing the code.</p> <p>Edit: here is my multipass generation code.</p> <pre><code>protected string getMultipass(UserData user_data) { // Encode the data into a JSON object JavaScriptSerializer s = new JavaScriptSerializer(); string json_data = s.Serialize(user_data); // Acquire the Web.config appSettings string site_key = "my_site_here"; string api_key = "my_key_here"; string iv = "OpenSSL for Ruby"; // Using byte arrays now instead of strings byte[] encrypted = null; byte[] bIV = Encoding.ASCII.GetBytes(iv); byte[] data = Encoding.ASCII.GetBytes(json_data); // XOR the first block (16 bytes) // once before the full XOR // so it gets double XORed for (var i = 0; i &lt; 16; i++) data[i] = (byte)(data[i] ^ bIV[i]); // Pad using block size of 16 bytes int pad = 16 - (data.Length % 16); Array.Resize(ref data, data.Length + pad); for (var i = 0; i &lt; pad; i++) data[data.Length - pad + i] = (byte)pad; // Use the AesManaged object to do the encryption using (AesManaged aesAlg = new AesManaged()) { aesAlg.IV = bIV; aesAlg.KeySize = 128; // Create the 16-byte salted hash SHA1 sha1 = SHA1.Create(); byte[] saltedHash = sha1.ComputeHash(Encoding.UTF8.GetBytes(api_key + site_key), 0, (api_key + site_key).Length); Array.Resize(ref saltedHash, 16); aesAlg.Key = saltedHash; // Encrypt using the AES managed object ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { csEncrypt.Write(data, 0, data.Length); csEncrypt.FlushFinalBlock(); } encrypted = msEncrypt.ToArray(); } } // Return the Base64-encoded encrypted data return Convert.ToBase64String(encrypted, Base64FormattingOptions.None) .TrimEnd("=".ToCharArray()) // Remove trailing "=" characters .Replace("+", "-") // Change "+" to "-" .Replace("/", "_"); // Change "/" to "_" } </code></pre> </div>

openssl_digest vs hash vs hash_hmac? SALT和HMAC之间的区别?

<div class="post-text" itemprop="text"> <p>I want to use SHA512 to store passwords. To do that, which of <code>openssl_digest</code>, <code>hash</code> and <code>hash_hmac</code> should I use and why?</p> <hr> <p>What is the difference between <code>SALT</code> &amp; <code>HMAC</code>?</p> <hr> <p>I just read that HMAC is built on top of hash function.</p> <p>So is <code>SHA512+SALT+HMAC</code> really necessary or <code>SHA512+SALT</code> or <code>SHA512+HMAC</code>?</p> </div>

SMS支付API集成

<div class="post-text" itemprop="text"> <p>Hi i need to integrate sms payments into site, hide element or link behind paywall, i have everything i need from company that backs these sms payments as well as text saying that the integration into site is fast and easy but for christs sake i have no idea how to make it work. i need to create this simple input for recieved sms code:</p> <p><a href="https://i.stack.imgur.com/m1AXw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m1AXw.jpg" alt="IMAGE"></a></p> <p>what i got from company is this guide:</p> <pre><code>2. Receiving MO SMS, Sending MT SMS Receiving MO SMS and sending MT SMS is handled by one HTTP POST request and response. Workflow: 1. A SMS sends MO SMS envelope object to client 2. Client responses with MT SMS envelope object back immediately Objects are JSON objects. MO SMS Envelope Name Type Description mosms MO SMS Object MO SMS MO SMS Object Name Type Required Description id int Required Unique ID of MO SMS dst_no string Required Destination short number – e.g. 8877 src_no string Required Source phone number of customer in international format only +421903123456 gtw_type int Required Mobile operator code 23101 – Orange SK 23102 – Telekom SK 23106 – O2 SK other message string Required Message – UTF8 encoding, unlimited characters (multipart SMS) hash string Required Hex (lowercase) encoded SHA1 HMAC from (id + src_no + dst_no + gtw_type + message) MT SMS Envelope Name Type Description status string ok, error mtsms MT SMS object MT SMS MT SMS Object Name Type Required Description message string Required Text message, max. 160 characters, GSM7 alphabet ASCII encoded, required bill_key string Required Dedicated billing code, e.g. MYPAY-00-00, required hash string Required Hex (lowercase) encoded SHA1 HMAC from (message + bill_key) ________________________________________________________________________________ 3. MT SMS statuses Workflow: 1. A SMS sends Status envelope object to client 2. Client responses back immediately Objects are JSON objects. Status Envelope Name Type Description mtstatus Status object Status Status Object Name Type Required Description id int Required Unique ID of MO SMS status string Required Billing/delivery status hash string Required Hex (lowercase) encoded SHA1 HMAC from (id + status) Statuses: D – Billed AND delivered S – Billed E – NOT billed and NOT delivered U – NOT delivered Status response Envelope Name Type Description status string ok, error ________________________________________________________________________________ 4. Examples 1. HTTP POST – MO and MT SMS Request ASMS -----------&gt; Client {"mosms": {"message": "Test", "gtw_type": 23106, "id": 123, "src_no": "+421903123456", "dst_no": "8877", "hash": "xxx"}} Response Client -----------&gt; ASMS {"status":"ok", "mtsms":{"message": "test mt sms", "bill_key": "MYPAY- 00-00", "hash": "xxx"}} {"status":"error", "mtsms":null} 2. HTTP POST – Billing/Delivery status Request ASMS -----------&gt; Client {"mtstatus": {"id": 123, "status": "D", "hash": "xxx"}} Response Client -----------&gt; ASMS {"status":"ok"} {"status":"error"} __________________________ </code></pre> <p>And these two sample demo codes:</p> <p>FIRST:</p> <pre><code>&lt;?php define('CONFIG_HASH_KEY', 'ABCDEFGH'); try { // read json data $postdata = file_get_contents("php://input"); $json = json_decode($postdata); $mosms = $json-&gt;mosms; // check hash $hashedStr = $mosms-&gt;id . $mosms-&gt;src_no . $mosms-&gt;dst_no . $mosms-&gt;gtw_type . $mosms-&gt;message; $hashedStr = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY); if($hashedStr != $mosms-&gt;hash) { throw new Exception('Hash error'); } //////////////////////////////////////////////////////////////////// // process SMS // your code // response example $response = array( 'status' =&gt; 'ok', 'mtsms' =&gt; array( 'message' =&gt; 'Dakujeme za platbu', 'bill_key' =&gt; 'MYPAY-01-00', ), ); // or $response = array( 'status' =&gt; 'ok', 'mtsms' =&gt; array( 'message' =&gt; 'SMS ste nenapisali v spravnom formate, prosim opravte sa...', 'bill_key' =&gt; 'MYPAY-00-00', ), ); //////////////////////////////////////////////////////////////////// $hashedStr = $response['mtsms']['message'] . $response['mtsms']['bill_key']; $response['mtsms']['hash'] = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY); } catch(Exception $e) { $response = array( 'status' =&gt; 'error', 'mtsms' =&gt; null, ); } echo json_encode($response); </code></pre> <p>SECOND:</p> <pre><code>&lt;?php define('CONFIG_HASH_KEY', 'ABCDEFGH'); try { // read json data $postdata = file_get_contents("php://input"); $json = json_decode($postdata); $mtstatus = $json-&gt;mtstatus; // check hash $hashedStr = $mtstatus-&gt;id . $mtstatus-&gt;status; $hashedStr = hash_hmac('SHA1', $hashedStr, CONFIG_HASH_KEY); if($hashedStr != $mtstatus-&gt;hash) { throw new Exception('Hash error'); } //////////////////////////////////////////////////////////////////// // process status // your code if($mtstatus-&gt;status === 'D') { //SMS was billed and delivered } else if($mtstatus-&gt;status === 'E') { //SMS was NOT billed and delivered } else if($mtstatus-&gt;status === 'S') { //SMS was billed } else if($mtstatus-&gt;status === 'U') { //SMS was NOT delivered } // response example $response = array( 'status' =&gt; 'ok' ); //////////////////////////////////////////////////////////////////// } catch(Exception $e) { $response = array( 'status' =&gt; 'error' ); } echo json_encode($response); </code></pre> <p>Can anyone help me/guide me with implementing this into site, as i already said i want to "hide" either element of site behind this paywall or link, thanks in advance :)</p> </div>

可捕获的致命错误:php json解码

<div class="post-text" itemprop="text"> <p>My json data</p> <pre><code>{ "total": 533489, "page": 1, "pagesize": 30, "questions": [ { "tags": [ "php", "html", "forms" ], "answer_count": 6, "favorite_count": 0, "question_timeline_url": "/questions/22075370/timeline", "question_comments_url": "/questions/22075370/comments", "question_answers_url": "/questions/22075370/answers", "question_id": 22075370, "owner": { "user_id": 3343981, "user_type": "registered", "display_name": "user3343981", "reputation": 3, "email_hash": "55d0eb4577a0ba9f9e428d445431b595" }, "creation_date": 1393520772, "last_activity_date": 1393522799, "up_vote_count": 0, "down_vote_count": 0, "view_count": 48, "score": 0, "community_owned": false, "title": "Issues with my form" }, { "tags": [ "php", "arrays" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22076141/timeline", "question_comments_url": "/questions/22076141/comments", "question_answers_url": "/questions/22076141/answers", "question_id": 22076141, "owner": { "user_id": 1479092, "user_type": "registered", "display_name": "Waldermort", "reputation": 470, "email_hash": "a00b970322ae60986ca4ed7629c7389b" }, "creation_date": 1393522754, "last_activity_date": 1393522754, "up_vote_count": 0, "down_vote_count": 0, "view_count": 12, "score": 0, "community_owned": false, "title": "How to find the first free key in an array" }, { "tags": [ "php", "codeigniter", "postgresql" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22076140/timeline", "question_comments_url": "/questions/22076140/comments", "question_answers_url": "/questions/22076140/answers", "question_id": 22076140, "owner": { "user_id": 3220020, "user_type": "registered", "display_name": "Kino", "reputation": 18, "email_hash": "839332924b8b9e3fdbc1465690378aa2" }, "creation_date": 1393522752, "last_activity_date": 1393522752, "up_vote_count": 0, "down_vote_count": 0, "view_count": 3, "score": 0, "community_owned": false, "title": "multiply 2 values from different table using codeigniter and postgresql foreach()" }, { "tags": [ "php" ], "answer_count": 1, "favorite_count": 0, "question_timeline_url": "/questions/22076037/timeline", "question_comments_url": "/questions/22076037/comments", "question_answers_url": "/questions/22076037/answers", "question_id": 22076037, "owner": { "user_id": 2719411, "user_type": "registered", "display_name": "Xander", "reputation": 12, "email_hash": "66a15843818fbcbc6aa01c19ec62aed0" }, "creation_date": 1393522498, "last_activity_date": 1393522735, "up_vote_count": 0, "down_vote_count": 0, "view_count": 24, "score": 0, "community_owned": false, "title": "Hide div based on time - PHP" }, { "tags": [ "php", ".htaccess", "ping", "password-protection" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22076119/timeline", "question_comments_url": "/questions/22076119/comments", "question_answers_url": "/questions/22076119/answers", "question_id": 22076119, "owner": { "user_id": 3361650, "user_type": "registered", "display_name": "user3361650", "reputation": 1, "email_hash": "84fd66f3c92515f9d2a45a2ca507a0ab" }, "creation_date": 1393522695, "last_activity_date": 1393522695, "up_vote_count": 0, "down_vote_count": 0, "view_count": 8, "score": 0, "community_owned": false, "title": "How to check website is online if it is password protected" }, { "tags": [ "php", "string", "random" ], "answer_count": 2, "favorite_count": 0, "question_timeline_url": "/questions/22075958/timeline", "question_comments_url": "/questions/22075958/comments", "question_answers_url": "/questions/22075958/answers", "question_id": 22075958, "owner": { "user_id": 1573630, "user_type": "registered", "display_name": "Michal S", "reputation": 157, "email_hash": "05e9ad26aa0851931b7cca5f130ac081" }, "creation_date": 1393522296, "last_edit_date": 1393522474, "last_activity_date": 1393522685, "up_vote_count": 1, "down_vote_count": 0, "view_count": 24, "score": 1, "community_owned": false, "title": "PHP - How to select random tag in the string" }, { "tags": [ "php", "symfony2", "symfony-forms" ], "answer_count": 1, "accepted_answer_id": 22076109, "favorite_count": 0, "question_timeline_url": "/questions/22075054/timeline", "question_comments_url": "/questions/22075054/comments", "question_answers_url": "/questions/22075054/answers", "question_id": 22075054, "owner": { "user_id": 245552, "user_type": "registered", "display_name": "Matthieu Napoli", "reputation": 7586, "email_hash": "48906ce482893497d2d7e017cd2f4352" }, "creation_date": 1393519990, "last_activity_date": 1393522680, "up_vote_count": 0, "down_vote_count": 0, "view_count": 9, "score": 0, "community_owned": false, "title": "Symfony form: customize the setter that is called" }, { "tags": [ "php", "wordpress", "sorting" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22076089/timeline", "question_comments_url": "/questions/22076089/comments", "question_answers_url": "/questions/22076089/answers", "question_id": 22076089, "owner": { "user_id": 2279387, "user_type": "registered", "display_name": "Tomas Kleinotas", "reputation": 7, "email_hash": "6ba9fc650c619efae62691c8456ca76f" }, "creation_date": 1393522645, "last_activity_date": 1393522645, "up_vote_count": 0, "down_vote_count": 0, "view_count": 3, "score": 0, "community_owned": false, "title": "How to sort category posts by meta_value if there are empty fields?" }, { "tags": [ "php", "mysql", "pdf", "embed", "blob" ], "answer_count": 1, "favorite_count": 0, "question_timeline_url": "/questions/22075847/timeline", "question_comments_url": "/questions/22075847/comments", "question_answers_url": "/questions/22075847/answers", "question_id": 22075847, "owner": { "user_id": 3346480, "user_type": "registered", "display_name": "Richard", "reputation": 1, "email_hash": "40e5ef3a529b8b66ec994c2b6a1d1555" }, "creation_date": 1393522007, "last_activity_date": 1393522615, "up_vote_count": 0, "down_vote_count": 0, "view_count": 3, "score": 0, "community_owned": false, "title": "embed pdf from blob to html/php page" }, { "tags": [ "php" ], "answer_count": 2, "favorite_count": 0, "question_timeline_url": "/questions/22075599/timeline", "question_comments_url": "/questions/22075599/comments", "question_answers_url": "/questions/22075599/answers", "question_id": 22075599, "owner": { "user_id": 3361419, "user_type": "registered", "display_name": "Eduardo", "reputation": 1, "email_hash": "e3561abf3d1b9969686df7113a4d82f6" }, "creation_date": 1393521373, "last_activity_date": 1393522615, "up_vote_count": 0, "down_vote_count": 6, "view_count": 16, "score": -6, "community_owned": false, "title": "Parse syntax error, unexpected end of file in C:\\xampp\\htdocs\\Pap\\create.php on line 292" }, { "tags": [ "php", "forms", "checkbox", "tcpdf" { "tags": [ "php", "composer-php", "directory-structure", "laravel-4.1" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075957/timeline", "question_comments_url": "/questions/22075957/comments", "question_answers_url": "/questions/22075957/answers", "question_id": 22075957, "owner": { "user_id": 1202367, "user_type": "registered", "display_name": "Claudio Ludovico Panetta", "reputation": 393, "email_hash": "2dca89fe809118d3a93d5a51e2cd28bd" }, "creation_date": 1393522295, "last_activity_date": 1393522295, "up_vote_count": 0, "down_vote_count": 0, "view_count": 5, "score": 0, "community_owned": false, "title": "Centralize vendor folder in Laravel 4.1.x" }, { "tags": [ "php", "sms" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075948/timeline", "question_comments_url": "/questions/22075948/comments", "question_answers_url": "/questions/22075948/answers", "question_id": 22075948, "owner": { "user_id": 3333903, "user_type": "registered", "display_name": "ArpanTechBuddy", "reputation": 1, "email_hash": "2abb3673c9cca94de81942f3b0b0488b" }, "creation_date": 1393522276, "last_activity_date": 1393522276, "up_vote_count": 0, "down_vote_count": 3, "view_count": 12, "score": -3, "community_owned": false, "title": "SMS from PHP to any number for free" }, { "tags": [ "php", "curl" ], "answer_count": 4, "favorite_count": 0, "question_timeline_url": "/questions/22075803/timeline", "question_comments_url": "/questions/22075803/comments", "question_answers_url": "/questions/22075803/answers", "question_id": 22075803, "owner": { "user_id": 1459253, "user_type": "registered", "display_name": "Siddesh Bhalke", "reputation": 671, "email_hash": "262597fd50cb34b6ddbc168b8f2d77a5" }, "creation_date": 1393521922, "last_activity_date": 1393522259, "up_vote_count": 0, "down_vote_count": 0, "view_count": 9, "score": 0, "community_owned": false, "title": "curl_init() has been disabled for security reasons" }, { "tags": [ "php", "wordpress", "rewrite" ], "answer_count": 2, "favorite_count": 0, "question_timeline_url": "/questions/18602715/timeline", "question_comments_url": "/questions/18602715/comments", "question_answers_url": "/questions/18602715/answers", "question_id": 18602715, "owner": { "user_id": 648938, "user_type": "registered", "display_name": "Scrooby", "reputation": 2164, "email_hash": "f280a3e68d054f94c2afa52c950a40b9" }, "creation_date": 1378248631, "last_edit_date": 1393521961, "last_activity_date": 1393522236, "up_vote_count": 0, "down_vote_count": 0, "view_count": 116, "score": 0, "community_owned": false, "title": "Page Not Found in title of WordPress page on template_redirect using include()" }, { "tags": [ "php", "mysql", "database-design" ], "answer_count": 1, "favorite_count": 0, "question_timeline_url": "/questions/22075748/timeline", "question_comments_url": "/questions/22075748/comments", "question_answers_url": "/questions/22075748/answers", "question_id": 22075748, "owner": { "user_id": 741156, "user_type": "registered", "display_name": "Momen M El Zalabany", "reputation": 957, "email_hash": "6819dd0de162410dcccd7b1b03bb5def" }, "creation_date": 1393521798, "last_edit_date": 1393522196, "last_activity_date": 1393522196, "up_vote_count": 0, "down_vote_count": 0, "view_count": 14, "score": 0, "community_owned": false, "title": "mysql design for employees working hours" }, { "tags": [ "php", "logging", "controller", "event-handling", "zend-framework2" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075903/timeline", "question_comments_url": "/questions/22075903/comments", "question_answers_url": "/questions/22075903/answers", "question_id": 22075903, "owner": { "user_id": 928044, "user_type": "registered", "display_name": "Vincent Caggiari", "reputation": 8, "email_hash": "3779e0b7d9bebe76c674bd59fa7016e9" }, "creation_date": 1393522170, "last_activity_date": 1393522170, "up_vote_count": 0, "down_vote_count": 0, "view_count": 4, "score": 0, "community_owned": false, "title": "zend 2 event manager wildcard + keywords" }, { "tags": [ "php", "wordpress" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075764/timeline", "question_comments_url": "/questions/22075764/comments", "question_answers_url": "/questions/22075764/answers", "question_id": 22075764, "owner": { "user_id": 1469270, "user_type": "registered", "display_name": "tmyie", "reputation": 515, "email_hash": "c7522e105f49699af313a6aba52a66bc" }, "creation_date": 1393521834, "last_edit_date": 1393522153, "last_activity_date": 1393522153, "up_vote_count": 0, "down_vote_count": 0, "view_count": 17, "score": 0, "community_owned": false, "title": "Loop through all posts, show attachment if there (WordPress)" }, { "tags": [ "php", "api", "paypal", "express", "checkout" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22074086/timeline", "question_comments_url": "/questions/22074086/comments", "question_answers_url": "/questions/22074086/answers", "question_id": 22074086, "owner": { "user_id": 3361211, "user_type": "registered", "display_name": "PmLvgn", "reputation": 1, "email_hash": "a4df4e1cb22b77c2e898d791c117a3a5" }, "creation_date": 1393517599, "last_edit_date": 1393522102, "last_activity_date": 1393522102, "up_vote_count": 0, "down_vote_count": 0, "view_count": 8, "score": 0, "community_owned": false, "title": "PHP Paypal API ExpressCheckout, i don't know what i sold in history details" }, { "tags": [ "php", "braintree" ], "answer_count": 1, "favorite_count": 0, "question_timeline_url": "/questions/22056863/timeline", "question_comments_url": "/questions/22056863/comments", "question_answers_url": "/questions/22056863/answers", "question_id": 22056863, "owner": { "user_id": 1233455, "user_type": "registered", "display_name": "JasonMortonNZ", "reputation": 967, "email_hash": "1d2bc25a4d7db82dd86c411afda88e8f" }, "creation_date": 1393462513, "last_activity_date": 1393522017, "up_vote_count": 1, "down_vote_count": 0, "view_count": 12, "score": 1, "community_owned": false, "title": "Braintree API in PHP success and currency issue" }, { "tags": [ "php" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075831/timeline", "question_comments_url": "/questions/22075831/comments", "question_answers_url": "/questions/22075831/answers", "question_id": 22075831, "owner": { "user_id": 3282713, "user_type": "registered", "display_name": "user3282713", "reputation": 1, "email_hash": "0fdeb1c7e8da488a6556ccc8386d0249" }, "creation_date": 1393521988, "last_activity_date": 1393521988, "up_vote_count": 0, "down_vote_count": 0, "view_count": 6, "score": 0, "community_owned": false, "title": "updating multiple items through checkbox in php" }, { "tags": [ "php", "html" ], "answer_count": 0, "favorite_count": 0, "question_timeline_url": "/questions/22075634/timeline", "question_comments_url": "/questions/22075634/comments", "question_answers_url": "/questions/22075634/answers", "question_id": 22075634, "owner": { "user_id": 2640557, "user_type": "registered", "display_name": "aveleon", "reputation": 20, "email_hash": "b20903bea6646401a4d88a7852ae6229" }, "creation_date": 1393521474, "last_edit_date": 1393521949, "last_activity_date": 1393521949, "up_vote_count": 1, "down_vote_count": 1, "view_count": 44, "score": 0, "community_owned": false, "title": "PHP is not working and cannot find out why (creating dynamic content)" }, { "tags": [ "php", "android", "web-services", "mobile", "service" ], "answer_count": 1, "favorite_count": 1, "closed_date": 1393520310, "closed_reason": "primarily opinion-based", "question_timeline_url": "/questions/22075094/timeline", "question_comments_url": "/questions/22075094/comments", "question_answers_url": "/questions/22075094/answers", "question_id": 22075094, "owner": { "user_id": 2715065, "user_type": "registered", "display_name": "Warde", "reputation": 285, "email_hash": "f265910523dec1dc1e11bb02b4af79a5" }, "creation_date": 1393520062, "last_edit_date": 1393521803, "last_activity_date": 1393521803, "up_vote_count": 0, "down_vote_count": 9, "view_count": 35, "score": -9, "community_owned": false, "title": "Need a service that sends the complete information of contacts to the server" } ] } </code></pre> <p>Getting below error when i try json_decode('abovedata'),</p> <p>ERROR:</p> <blockquote> <p>Catchable fatal error: Object of class stdClass could not be converted to string in F:\xamp\htdocs\xampp\curl.php on line 12</p> </blockquote> <p>How can i read each key values from above json data ?</p> </div>

<已解决>nginx配置问题 急急急

大家好 最近买了个域名,租了一台服务器(centos,yum安装 )但再nginx的配置上出了问题 这是我的/etc/nginx/nginx.conf ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } } ``` 我把虚拟主机的配置放在了/etc/nginx/conf.d/目录下了 文件名:liangzda.com.conf 配置如下: ``` server { listen 80; server_name www.liangzda.com; location /{ proxy_pass http://localhost:8080; } } ``` 我安装了tomcat,监听8080端口 打算把访问www.liangzda.com的请求转发给tomcat 一顿配置之后,重启nginx时,提示出错,查看日志文件如下: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/liangzda.com.conf:1 请问应该怎么办? 最后自己发现是自己在conf.d 和 default.conf里面重复放了配置文件 所以出错,我把两个配置文件都删除了,然后自己建了一个文件夹 vhost 然后把配置文件添加到里面 ,再在nginx.conf里面添加include vhost/*.conf 就好了

PHP sha512 hmac产生的值与JS hmac不同

<div class="post-text" itemprop="text"> <p>Here is some of my JS code. I am creating the hmac using Crypto, then passing in the date and signature as request headers to use in PHP:</p> <pre class="lang-js prettyprint-override"><code>events: { proxyReq: (proxyReq, req) =&gt; { const date = Date.now(); const API_KEY = 125; const API_SECRET_KEY = 'abc'; const s = new Buffer(API_SECRET_KEY, 'base64'); const message = req.method + req.url + date; let hmac = crypto.createHmac('sha512', s); const signature = hmac.update(message).digest('base64'); proxyReq.setHeader('x-api-key', API_KEY); proxyReq.setHeader('x-api-signature', signature); proxyReq.setHeader('x-api-date', date); }, }, </code></pre> <p>Here is my PHP function where I try to reproduce the same hmac using hash_hmac():</p> <pre><code>public function handle($request, \Closure $next) { try { $API_SECRET_KEY = 'abc'; $method = $request-&gt;method(); $url = $request-&gt;path(); $date = $request-&gt;header('x-api-date'); $client_key = $request-&gt;header('x-api-key'); $client_signature = $request-&gt;header('x-api-signature'); $message = $method . $url . $date; $hmac = base64_encode(hash_hmac('sha512', $message, base64_decode($API_SECRET_KEY), true)); $all['x-api-date'] = $date; $all['x-api-signature'] = $client_signature; $all['x-api-key'] = $client_key; Log::error($client_signature); Log::error($hmac); return $next($request); } </code></pre> <p>My last outputs:</p> <pre><code>[2018-07-10 14:23:57] local.ERROR: D0xis7BbxLBg6eWBlIT0ZSnhzk4c3Z3Ore9B16bNZow8xoinfM1zuMlS+lZ6pcOqRRHuupodUVFAIHfv89v4xw== [2018-07-10 14:23:57] local.ERROR: Uypk5ZAd/I6E6sMi9UjIMyMxVhuQm7MatZbKCcGjGjsE2JqqrvTRYuJAR/SSde10eHAkPIz0g24CSZp0G+833A== </code></pre> <p>Can someone explain to me what I am doing wrong? I made sure to use base64 encoding/decoding and made sure the values passed into the hmac function were the same as the headers.</p> <p>I appreciate any help!</p> </div>

转换哈希甚至ruby像php的hash_hmac()

<div class="post-text" itemprop="text"> <p>PHP version:</p> <pre><code>hash_hmac('sha384', data, privateKey, true); </code></pre> <p>I have rewritten the above PHP code to ruby code below, but similar results were not obtained.</p> <p>Ruby version:</p> <pre><code>OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha384"), privateKey, data) </code></pre> <p>PHP is raw binary data, Ruby does not have such an option.</p> <p>How can I rewrite the PHP function into a Ruby function?</p> </div>

谷歌关闭通过PHP与Externs

<div class="post-text" itemprop="text"> <p>I am trying to use Google Closure but called through a php library. </p> <p>This is the code I'm trying to work with</p> <pre><code>https://code.google.com/p/php-closure/ </code></pre> <p>So far it seems to be working well. However I now need to use the "Externs" feature of Google Closure. </p> <p>I have gone through the php library code but I am unsure on how to add this feature. The library appears to call the Google Closure online API code, so I assume to add the externs feature I just need to pass the correct string attached to the correct variable. </p> <p>I won't post the entire library here as it would be hard to read, but the efforts I've made to incorporate this feature. </p> <p>To begin I added the variable to the library</p> <pre><code>var $_srcs = array(); var $_mode = "WHITESPACE_ONLY"; var $_warning_level = "DEFAULT"; var $_use_closure_library = false; var $_pretty_print = false; var $_debug = true; var $_cache_dir = ""; var $_code_url_prefix = ""; var $_extern_file = ""; //my new code </code></pre> <p>add to the hash function</p> <pre><code>function _getHash() { return md5(implode(",", $this-&gt;_srcs) . "-" . $this-&gt;_mode . "-" . $this-&gt;_warning_level . "-" . $this-&gt;_use_closure_library . "-" . $this-&gt;_pretty_print . "-" . $this-&gt;_extern_file . "-" . //here again $this-&gt;_debug); } </code></pre> <p>add to get params list</p> <pre><code>function _getParamList() { $params = array(); ... $params["warning_level"] = $this-&gt;_warning_level; $params["extern_file"] = $this-&gt;_extern_file; //again here if ($this-&gt;_pretty_print) $params["formatting"] = "pretty_print"; if ($this-&gt;_use_closure_library) $params["use_closure_library"] = "true"; $params["output_info_1"] = "compiled_code"; $params["output_info_2"] = "statistics"; $params["output_info_3"] = "warnings"; $params["output_info_4"] = "errors"; return $params; } </code></pre> <p>my add externs file function</p> <pre><code>function externs($file) { $this-&gt;_extern_file = $file; return $this; } </code></pre> <p>then my user call</p> <pre><code>$c-&gt;add("js/my-app.js") -&gt;add("js/popup.js") -&gt;externs("js/externs.js") //new code -&gt;cacheDir("/tmp/js-cache/") -&gt;write(); </code></pre> <p>When trying to execute the code I get the same result as the original code. It appears the externs file that I'm trying to pass isn't being processed. </p> <p>If anyone else is interested in this feature / library please feel free to post any ideas. </p> <p>Thanks.</p> </div>

安全注册,使用hash()登录

<div class="post-text" itemprop="text"> <pre><code>&lt;?php $conn=mysqli_connect("localhost", "root", "","users"); if (!$conn) { echo "Bad connection!!!"; } $user_name=$_POST['user_name']; $user_password=$_POST['user_password']; $sql_check=mysqli_query($conn, "SELECT user_name, password FROM user_info WHERE user_name='$user_name' AND password='$user_password'") or die("Bad sql query"); if (mysqli_num_rows($sql_check)&gt;0) { echo "user exists"; } else { $sql_insert=mysqli_query($conn, "INSERT INTO user_info (id, user_name, password) VALUES (null,'$user_name', '$user_password')"); echo "New user added!!!"; } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="POST" action="pdo_konekcija.php"&gt; &lt;input type="text" name="user_name"&gt; &lt;input type="password" name="user_name"&gt; &lt;input type="submit" name="btn_submit" value="REGISTER"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have basic form for user registration. I can't figure best way for checking if the user exists or not, so if not I want to register new user as you can see from sql statements. How can I include hash() for password for the user_password field? Both fields must be filled for checking and registering process. Can I use this kind of mysql I procedural way for preventing sql injection or not? I am building register/login from scratch so need help, thank you all.</p> </div>

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

人工智能-计算机视觉实战之路(必备算法+深度学习+项目实战)

系列课程主要分为3大阶段:(1)首先掌握计算机视觉必备算法原理,结合Opencv进行学习与练手,通过实际视项目进行案例应用展示。(2)进军当下最火的深度学习进行视觉任务实战,掌握深度学习中必备算法原理与网络模型架构。(3)结合经典深度学习框架与实战项目进行实战,基于真实数据集展开业务分析与建模实战。整体风格通俗易懂,项目驱动学习与就业面试。 建议同学们按照下列顺序来进行学习:1.Python入门视频课程 2.Opencv计算机视觉实战(Python版) 3.深度学习框架-PyTorch实战/人工智能框架实战精讲:Keras项目 4.Python-深度学习-物体检测实战 5.后续实战课程按照自己喜好选择就可以

linux2.6.1内核源码注释

包含LINUX内核同步、信号、内存、调度、文件系统、网络系统、时钟等部分的源码注释。前后历时三年,算是干货。

Python可以这样学(第四季:数据分析与科学计算可视化)

董付国老师系列教材《Python程序设计(第2版)》(ISBN:9787302436515)、《Python可以这样学》(ISBN:9787302456469)配套视频,在教材基础上又增加了大量内容,通过实例讲解numpy、scipy、pandas、statistics、matplotlib等标准库和扩展库用法。

u-boot-2015.07.tar.bz2

uboot-2015-07最新代码,喜欢的朋友请拿去

Vue.js 2.0之全家桶系列视频课程

基于新的Vue.js 2.3版本, 目前新全的Vue.js教学视频,让你少走弯路,直达技术前沿! 1. 包含Vue.js全家桶(vue.js、vue-router、axios、vuex、vue-cli、webpack、ElementUI等) 2. 采用笔记+代码案例的形式讲解,通俗易懂

MySQL 8.0.19安装教程(windows 64位)

话不多说直接开干 目录 1-先去官网下载点击的MySQL的下载​ 2-配置初始化的my.ini文件的文件 3-初始化MySQL 4-安装MySQL服务 + 启动MySQL 服务 5-连接MySQL + 修改密码 先去官网下载点击的MySQL的下载 下载完成后解压 解压完是这个样子 配置初始化的my.ini文件的文件 ...

零基础学C#编程—C#从小白到大咖

本课程从初学者角度出发,提供了C#从入门到成为程序开发高手所需要掌握的各方面知识和技术。 【课程特点】 1 由浅入深,编排合理; 2 视频讲解,精彩详尽; 3 丰富实例,轻松易学; 4 每章总结配有难点解析文档。 15大章节,228课时,1756分钟与你一同进步!

微信公众平台开发入门

本套课程的设计完全是为初学者量身打造,课程内容由浅入深,课程讲解通俗易懂,代码实现简洁清晰。通过本课程的学习,学员能够入门微信公众平台开发,能够胜任企业级的订阅号、服务号、企业号的应用开发工作。 通过本课程的学习,学员能够对微信公众平台有一个清晰的、系统性的认识。例如,公众号是什么,它有什么特点,它能做什么,怎么开发公众号。 其次,通过本课程的学习,学员能够掌握微信公众平台开发的方法、技术和应用实现。例如,开发者文档怎么看,开发环境怎么搭建,基本的消息交互如何实现,常用的方法技巧有哪些,真实应用怎么开发。

java jdk 8 帮助文档 中文 文档 chm 谷歌翻译

JDK1.8 API 中文谷歌翻译版 java帮助文档 JDK API java 帮助文档 谷歌翻译 JDK1.8 API 中文 谷歌翻译版 java帮助文档 Java最新帮助文档 本帮助文档是使用谷

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

编程实现学生基本信息管理程序

编程实现学生基本信息管理程序。学生基本信息包括:学号、姓名、性别、年龄、班级、学院、专业等。具体实现的管理功能如下: (1) 输入并显示多个学生的基本信息; (2) 可根据需要实现学生信息的添加; (

机器学习实战系列套餐(必备基础+经典算法+案例实战)

机器学习实战系列套餐以实战为出发点,帮助同学们快速掌握机器学习领域必备经典算法原理并结合Python工具包进行实战应用。建议学习顺序:1.Python必备工具包:掌握实战工具 2.机器学习算法与实战应用:数学原理与应用方法都是必备技能 3.数据挖掘实战:通过真实数据集进行项目实战。按照下列课程顺序学习即可! 课程风格通俗易懂,用最接地气的方式带领大家轻松进军机器学习!提供所有课程代码,PPT与实战数据,有任何问题欢迎随时与我讨论。

YOLOv3目标检测实战:训练自己的数据集

YOLOv3是一种基于深度学习的端到端实时目标检测方法,以速度快见长。本课程将手把手地教大家使用labelImg标注和使用YOLOv3训练自己的数据集。课程分为三个小项目:足球目标检测(单目标检测)、梅西目标检测(单目标检测)、足球和梅西同时目标检测(两目标检测)。 本课程的YOLOv3使用Darknet,在Ubuntu系统上做项目演示。包括:安装Darknet、给自己的数据集打标签、整理自己的数据集、修改配置文件、训练自己的数据集、测试训练出的网络模型、性能统计(mAP计算和画出PR曲线)和先验框聚类。 Darknet是使用C语言实现的轻型开源深度学习框架,依赖少,可移植性好,值得深入探究。 除本课程《YOLOv3目标检测实战:训练自己的数据集》外,本人推出了有关YOLOv3目标检测的系列课程,请持续关注该系列的其它课程视频,包括: 《YOLOv3目标检测实战:交通标志识别》 《YOLOv3目标检测:原理与源码解析》 《YOLOv3目标检测:网络模型改进方法》 敬请关注并选择学习!

Python+OpenCV计算机视觉

Python+OpenCV计算机视觉系统全面的介绍。

土豆浏览器

土豆浏览器可以用来看各种搞笑、电影、电视剧视频

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

玩转Linux:常用命令实例指南

人工智能、物联网、大数据时代,Linux正有着一统天下的趋势,几乎每个程序员岗位,都要求掌握Linux。本课程零基础也能轻松入门。 本课程以简洁易懂的语言手把手教你系统掌握日常所需的Linux知识,每个知识点都会配合案例实战让你融汇贯通。课程通俗易懂,简洁流畅,适合0基础以及对Linux掌握不熟练的人学习; 【限时福利】 1)购课后按提示添加小助手,进答疑群,还可获得价值300元的编程大礼包! 2)本月购买此套餐加入老师答疑交流群,可参加老师的免费分享活动,学习最新技术项目经验。 --------------------------------------------------------------- 29元=掌握Linux必修知识+社群答疑+讲师社群分享会+700元编程礼包。 &nbsp;

基于STM32的电子时钟设计

时钟功能 还有闹钟功能,温湿度功能,整点报时功能 你值得拥有

Python数据清洗实战入门

本次课程主要以真实的电商数据为基础,通过Python详细的介绍了数据分析中的数据清洗阶段各种技巧和方法。

Git 实用技巧

这几年越来越多的开发团队使用了Git,掌握Git的使用已经越来越重要,已经是一个开发者必备的一项技能;但很多人在刚开始学习Git的时候会遇到很多疑问,比如之前使用过SVN的开发者想不通Git提交代码为什么需要先commit然后再去push,而不是一条命令一次性搞定; 更多的开发者对Git已经入门,不过在遇到一些代码冲突、需要恢复Git代码时候就不知所措,这个时候哪些对 Git掌握得比较好的少数人,就像团队中的神一样,在队友遇到 Git 相关的问题的时候用各种流利的操作来帮助队友于水火。 我去年刚加入新团队,发现一些同事对Git的常规操作没太大问题,但对Git的理解还是比较生疏,比如说分支和分支之间的关联关系、合并代码时候的冲突解决、提交代码前未拉取新代码导致冲突问题的处理等,我在协助处理这些问题的时候也记录各种问题的解决办法,希望整理后通过教程帮助到更多对Git操作进阶的开发者。 本期教程学习方法分为“掌握基础——稳步进阶——熟悉协作”三个层次。从掌握基础的 Git的推送和拉取开始,以案例进行演示,分析每一个步骤的操作方式和原理,从理解Git 工具的操作到学会代码存储结构、演示不同场景下Git遇到问题的不同处理方案。循序渐进让同学们掌握Git工具在团队协作中的整体协作流程。 在教程中会通过大量案例进行分析,案例会模拟在工作中遇到的问题,从最基础的代码提交和拉取、代码冲突解决、代码仓库的数据维护、Git服务端搭建等。为了让同学们容易理解,对Git简单易懂,文章中详细记录了详细的操作步骤,提供大量演示截图和解析。在教程的最后部分,会从提升团队整体效率的角度对Git工具进行讲解,包括规范操作、Gitlab的搭建、钩子事件的应用等。 为了让同学们可以利用碎片化时间来灵活学习,在教程文章中大程度降低了上下文的依赖,让大家可以在工作之余进行学习与实战,并同时掌握里面涉及的Git不常见操作的相关知识,理解Git工具在工作遇到的问题解决思路和方法,相信一定会对大家的前端技能进阶大有帮助。

计算机组成原理算法实现

计算机组成原理算法实现,能够实现定点小数的机器数表示、定点小数的变形补码加减运算、定点小数的原码一位乘法运算和浮点数的加减运算。

为linux系统设计一个简单的二级文件系统

实验目的: 通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。 实验要求: 为linux系统设计一个简单的二级文件系统。要求做到以下几点: (1)可以实现下列几条命令(至少4条)

几率大的Redis面试题(含答案)

本文的面试题如下: Redis 持久化机制 缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级等问题 热点数据和冷数据是什么 Memcache与Redis的区别都有哪些? 单线程的redis为什么这么快 redis的数据类型,以及每种数据类型的使用场景,Redis 内部结构 redis的过期策略以及内存淘汰机制【~】 Redis 为什么是单线程的,优点 如何解决redis的并发竞争key问题 Red...

机器学习初学者必会的案例精讲

通过六个实际的编码项目,带领同学入门人工智能。这些项目涉及机器学习(回归,分类,聚类),深度学习(神经网络),底层数学算法,Weka数据挖掘,利用Git开源项目实战等。

网络工程师小白入门--【思科CCNA、华为HCNA等网络工程师认证】

本课程适合CCNA或HCNA网络小白同志,高手请绕道,可以直接学习进价课程。通过本预科课程的学习,为学习网络工程师、思科CCNA、华为HCNA这些认证打下坚实的基础! 重要!思科认证2020年2月24日起,已启用新版认证和考试,包括题库都会更新,由于疫情原因,请关注官网和本地考点信息。题库网络上很容易下载到。

2019全国大学生数学建模竞赛C题原版优秀论文

2019全国大学生数学建模竞赛C题原版优秀论文,PDF原版论文,不是图片合成的,是可编辑的文字版。共三篇。 C044.pdf C137.pdf C308.pdf

土豆SDK(Java版)-非官方

由于土豆SDK一直建设中,最近几天抽空写了一套java的SDK。包含了现有的所有请求协议。本套SDK中仅提供了oAuth的方式(引用oAuth.net的java版示例),并没有在框架中实现,涉及到登录

Android小项目——新闻APP(源码)

Android小项目——新闻APP(源码),一个很简单的可以练手的Android Demo Ps:下载之前可以先看一下这篇文章——https://blog.csdn.net/qq_34149526/a

实用主义学Python(小白也容易上手的Python实用案例)

原价169,限时立减100元! 系统掌握Python核心语法16点,轻松应对工作中80%以上的Python使用场景! 69元=72讲+源码+社群答疑+讲师社群分享会&nbsp; 【哪些人适合学习这门课程?】 1)大学生,平时只学习了Python理论,并未接触Python实战问题; 2)对Python实用技能掌握薄弱的人,自动化、爬虫、数据分析能让你快速提高工作效率; 3)想学习新技术,如:人工智能、机器学习、深度学习等,这门课程是你的必修课程; 4)想修炼更好的编程内功,优秀的工程师肯定不能只会一门语言,Python语言功能强大、使用高效、简单易学。 【超实用技能】 从零开始 自动生成工作周报 职场升级 豆瓣电影数据爬取 实用案例 奥运冠军数据分析 自动化办公:通过Python自动化分析Excel数据并自动操作Word文档,最终获得一份基于Excel表格的数据分析报告。 豆瓣电影爬虫:通过Python自动爬取豆瓣电影信息并将电影图片保存到本地。 奥运会数据分析实战 简介:通过Python分析120年间奥运会的数据,从不同角度入手分析,从而得出一些有趣的结论。 【超人气老师】 二两 中国人工智能协会高级会员 生成对抗神经网络研究者 《深入浅出生成对抗网络:原理剖析与TensorFlow实现》一书作者 阿里云大学云学院导师 前大型游戏公司后端工程师 【超丰富实用案例】 0)图片背景去除案例 1)自动生成工作周报案例 2)豆瓣电影数据爬取案例 3)奥运会数据分析案例 4)自动处理邮件案例 5)github信息爬取/更新提醒案例 6)B站百大UP信息爬取与分析案例 7)构建自己的论文网站案例

相关热词 c# cad插入影像 c#设计思想 c#正则表达式 转换 c#form复制 c#写web c# 柱形图 c# wcf 服务库 c#应用程序管理器 c#数组如何赋值给数组 c#序列化应用目的博客园
立即提问