Implementation of Flash Local encryption

Source: Internet
Author: User
Tags character set md5
Encryption first let's assume a situation.

We want to do a flash, there are a few words, just want to give people who know the password to see. The usual practice is to detect whether the user's input equals the password and then display it. However, since Flash is an open structure, the SWF file can be disassembled and then see the password, which makes it illegal to see what you want to protect.

But if you encrypt the password through an irreversible algorithm, then you have the SWF inside. The password that is entered by the user is also encrypted, and then it is more equal to the string after the encryption. Because the password stored in the SWF is not reversible AH ~ ~

There are many kinds of irreversible encryption algorithms, the most popular is the MD series, now is MD5. MD5 can compute the characteristics of a recognized string and then boil it down to a 32-byte long string, and a little change in the source string can result in a huge variation in the character string.

According to an example:

The MD5 of "ABC" is 900150983CD24FB0D6963F7D28E17F72.
The "ABB" MD5 is ea01e5fd8e4d8832825acdd20eac5104.

Why does it say irreversible?

According to an example

Question: What number does 1000 add up to?
The answer is not know ~
If it's two digits, then we can have 1+999 or 500+500 or ... But what about three, four, until n numbers? That means we can't know what the original numbers are, and the chances of guessing are very small. And MD5 is the same principle, the characteristics of each character added and then added, naturally it is difficult to guess what the original thing ~

Then we have the password detection ~ Time to need a reversible encryption algorithm to deal with the things we want to save, because to restore AH ~ ~ This kind of algorithm many, I chose the more popular des algorithm

This is the definition of the DES function.
Des ("Password", "Encrypted text", mode)

When the pattern =1, DES returns the encrypted value
When the pattern =0, DES returns the decrypted value

But since the value returned by DES is not necessarily in the universal character set, I did a bit of processing to turn Des's value into a 16 string to prevent errors from arising.

The reason is very clear, how to use it ~ ~ First, we will create the MD5 value of the password, using the following function:

/*
E-mail:tsxy@21cn.com
Moon.blue
*/
var hexcase = 0;
var b64pad = "";
var strsize

function MD5 (s) {return Binl2hex (CORE_MD5 (Str2binl (s), s.length * strsize));
function B64_md5 (s) {return binl2b64 (CORE_MD5 (Str2binl (s), s.length * strsize));
function Str_md5 (s) {return binl2str (CORE_MD5 (Str2binl (s), s.length * strsize));
function Hex_hmac_md5 (key, data) {return Binl2hex (CORE_HMAC_MD5 (key, data));}
function B64_hmac_md5 (key, data) {return binl2b64 (CORE_HMAC_MD5 (key, data));}
function Str_hmac_md5 (key, data) {return binl2str (CORE_HMAC_MD5 (key, data));}

function Core_md5 (x, Len) {



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.