Import java. Io .*;
Public class mimebase64 {/*This is a simple base64 encoding program.By ROC Chen rocanny@163.com.Base64 uses 65 characters from a subset of the US-ASCII, each representing 6 CharactersTherefore, the base64 Value of "M" is 38, and the binary format is 100110.
For text strings, the encoding process is as follows. For example, "men ":
First conve
1. JDK/** * Use JDK to implement Base64 encryption */public static void JdkBase64 () {try {Base64encoder encoder = new Base64encoder (); String encode = Encoder.encode (Src.getbytes ()); System.out.println ("Encode:" + encode); Base64decoder decoder = new Base64decoder (); System.out.println ("Decode:" + New String (Decoder.decodebuffer (encode));} catch (IOException e) {e.printstacktrace ();}}In the case of using this method, there may be a situation
Control character in cookie value, consider BASE64 encoding your value, java operation cookie will report an error in Chinese, the report will report
The project uses cookies to save Chinese characters, but the following error is reported:
Control character in cookie value, consider BASE64 encoding your value
It indicates that the value saved to the cookie has
Original: "Project Analysis" uses C # to rewrite Base64.decodebase64 and inflater decoding in JavaA recent migration of project Services is underway to port the Java Services program to the Dotnet platform.In a Java program, there is an HTTP request data header that contains a BASE64 encoded string, for example:ejyvjme
This topic is mainly about Java security, it should be considered a hodgepodge, but not lack of practicality, as a summary, when used can be used as a reference.1, using BASE64 plus decryptionIn Java encryption technology, BASE64 is the simplest and most basic encryption technology. See the following example:Importjava
A short time ago to do a small project, to upload a picture to the server side, the function is very simple, the server side with. NET MVC4, the client is the WinForm program.Yesterday the leader said that the client to transplant a class of Android program, it took a little time to do a, when the transfer of Java to find out the string is not the same as C #, can not be restored.Because BASE64 is a unified
First, let's look at the code in Java that decrypts the string:Secret keyPrivate String key = "123456789012345678901234";Decryption process, the first decryption with Base64, and then 3DES for the second decryption, to get the plaintextpublic string Decryptthreedesecb (String src) throws Exception {Desedekeyspec DKs = new Desedekeyspec (key.getbytes (CharSet));Secretkeyfactory keyfactory = secretkeyfactory.
Sun.misc. Base64encoder The /base64decoder class is not part of the JDK standard library category, but it is included in the JDK and can be used directly, but this does not have Java doc, which is not a recommended tool class in the JDK. It is highly recommended not to use Sun.misc, which is not safe. Bouncycastle jar Package:http://www.bouncycastle.org/latest_releases.html Package Com.tvm.mrz.security.base64;import Java.io.ioexception;import or
=is.read (buffer))! =-1 ) {
//Use the output stream to write data to buffer, where the intermediate parameters represent where to begin reading, and Len represents the length of the read
Outstream.write (buffer, 0, Len);
}
//byte array Base64 encoding
returnNew Base64encoder (). Encode (Outstream.tobytearray ());
}catch (Exception e) {
E.printstacktrace ();
} Download
finally {
if (IS! = null)
{
Try {
Is.close ();
}
The project service is being transplanted recently.ProgramTo the DOTNET platform.
In a Java program, an HTTP request data header contains a base64 encoded string, for example:
Required/uqjcj06y7jfhwax3ahha =
Now you need to convert this string to the original string, which contains a lot of important information.
Let's take a look at how Java implements t
algorithms: DES algorithm, 3DES algorithm, TDEA algorithm, Blowfish algorithm, RC5 algorithm, IDEA algorithm,AES Algorithm.
Asymmetric encryption algorithm:RSA, Elgamal, backpack algorithm, Rabin, D-H, ECC.
Typical hash algorithms: MD2, MD4,MD5And SHA-1 (the purpose is to convert any long input to a fixed long output by using an algorithm, and ensure that the input changes slightly and the output is different, and reverse decryption is not allowed)
5. Classic Algorithms
AES (symmetric), RSA (as
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.