two commonly used encryption methods in C #:Personal mark, for reference only. Public Static classExtends {/// ///HMAC SHA256/// /// /// Public Static stringSHA256 ( This stringstr) { byte[] Sha256data =Encoding.UTF8.GetBytes (str); SHA256Managed sha256=Newsha256managed (); byte[] buffer =
Objective
Open interface in order to avoid being called by others, wasting server resources, which involves signing (Signature) encryption
The API uses the signature method (Signature) to authenticate the interface (authentication). Each request needs to include the signature information in the request to verify the user's identity.
Interface signature
1. According to the requirements of the document, look at the interface signature rules, each company's signature rules are diff
(plainbytes),//Base64.default);// return hash; } catch (Exception e) {e.printstacktrace (); } return Null }
It is broadly divided into these sections to analyze:
1. Get SHA256 Instances
2. Generate an encryption key
3. Initialize the SHA256 instance with this encryption key
4. Use this instance to encrypt the generated hash based on the provided string
4. Finally, the whole thing is to
If your API Service Security Authentication Protocol requires the hmac_sha1 method to encode information, and your service is implemented by PHP, the client is implemented by JAVA, in order to correctly compare the signature, a matching encoding method needs to be established between the two. the PHP side is as follows: define (ID, 123456); define (KEY, k123456); $ strToSign
If your API Service Security Authentication Protocol requires the hmac_sha1 m
OrderThe second one-way encryption algorithm--sha is briefly introduced in the previous article, and the Java code of SHA-1 is also given. Children's shoes with this need can be consulted. Today this article will introduce the third one-way encryption algorithm--hmac, in fact, this encryption algorithm is not so common, at least, before I write a series of blogs, I have not heard of it. Of course, this is n
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.