In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how to parse the Java coding summary algorithm examples, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
URL encoding and decoding
String s = "Hello, World!" ; / / URL encoding String urlEncodedString = URLEncoder.encode (s, "UTF-8"); / / URL decoding String urlDecodedString = URLDecoder.decode (urlEncodedString, "UTF-8")
Base64 encoding and decoding
/ / Base64 Encoding String base64EncodedString = Base64 .getEncoder () / = .withoutPadding () after removing Base64. EncodeToString ("Hello, World!!" .getBytes (StandardCharsets.UTF_8); / / Base64 decoding byte [] base64DecodedByteArray = Base64.getDecoder () .decode (base64EncodedString); String base64DecodedString = new String (base64DecodedByteArray, StandardCharsets.UTF_8)
Byte [] to hexadecimal string
The following summary algorithm will be used to visualize the results.
/ * * byte [] bitwise conversion to hexadecimal String * @ param aData byte [] * @ return byte [] bitwise conversion to hexadecimal String * / public static String byteArrayToHexString (byte [] aData) {final char [] hexChars = "0123456789abcdef" .toCharArray (); / / A byte represents StringBuilder stringBuilder = new StringBuilder (aData.length * 2) with two hexadecimal characters For (byte b: aData) {/ / High 4 bits converted to hexadecimal stringBuilder.append (hexChars [(b > 4) & 0x0f]); / / low 4 bits converted to hexadecimal stringBuilder.append (Hexchars [b & 0x0f]);} return stringBuilder.toString ();}
MD5 algorithm
/ / the parameter is the name of the summary algorithm MessageDigest messageDigest = MessageDigest.getInstance ("MD5"); / / the following two lines of code are equivalent to messageDigest.update ("Hello, World!" .getBytes (StandardCharsets.UTF_8); messageDigest.update ("Hello," .getBytes (StandardCharsets.UTF_8)); messageDigest.update ("World!" .getBytes (StandardCharsets.UTF_8); byte [] md5Bytes = messageDigest.digest ()
SHA1 algorithm
/ / SHA256 just change the name of the algorithm MessageDigest messageDigest = MessageDigest.getInstance ("SHA1"); / / the following two lines of code are equivalent to messageDigest.update ("Hello, World!" .getBytes (StandardCharsets.UTF_8); messageDigest.update ("Hello," .getBytes (StandardCharsets.UTF_8)); messageDigest.update ("World!" .getBytes (StandardCharsets.UTF_8); byte [] md5Bytes = messageDigest.digest ()
In this paper, the sample code is introduced in great detail, which has a certain reference value for everyone's study or work.
The above content is how to parse the example of Java coding summary algorithm. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.