In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.