In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Due to business requirements, the php project uses SHA-256 signature and extension to connect a java api. Together with java students, we study the SHA-256 signature and extension of php and java, and share the operations:
Java demo is as follows:
Public class SignUtils {
Public static String toSign (String data, String salt) {
String s = data + salt
Byte [] sign
Try {
Sign = SHA256.Digest.getInstance ("SHA-256") .digest (s.getBytes (Charset.forName ("UTF-8")
Byte [] signBase = Base64.getEncoder () .encode (sign)
Return new String (signBase,Charset.forName ("UTF-8"))
} catch (Exception e) {
Throw new Exception ("signature exception!")
}
}
}
String text = "lwy"
String salt = "lwy20190803"
String signData = SignUtils.toSign (text, salt)
System.ount.println (signData)
Output: QXulYxjtlJ1e/hEaeTKSjnSY8Xf37GuLRwAsnkEWN94=
Php demo is as follows:
Class SignUtils {
Public static function toSign ($data,$salt) {
$string = $data.$salt
$data = hash ('sha256', $string)
Return base64_encode (hex2bin ($data))
}
}
$sign = new SignUtils ()
$salt = "lwy20190803"
$str = "lwy"
$signData = $sign- > toSign ($str,$salt)
Echo "signature string:", $str.$salt
Echo "signature result:", $signData
Output result:
Signature string: lwylwy20190803
Signature result: QXulYxjtlJ1e/hEaeTKSjnSY8Xf37GuLRwAsnkEWN94=
This demo thanks Brother Abo for helping with the debugging step by step.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.