ssi

该文档简述三个框架的整合

session详解
http://blog.sina.com.cn/s/blog_69c7bf570100u3lx.html

<style type="text/css">
li.color {
color: red;
background: green;
}

li {
width: 80px;
height: 20px;
}
</style>
<script type="text/javascript">
$(function() {
$("#nav ul li").click(function() {
$(this).addClass("color").siblings().removeClass();
})
})
</script>
</head>

<body>
jquery 练习
<br>

<form action="">
<input id="username"type="text" name="name" value="ddd" />
</form>
1353064296) for encryption, the encrypted result on linux is different from that on windows; and the encrypted ciphertext cannot be decrypted on linux, and an exception is thrown. Reason: After checking, locate the method of generating KEY, that is, the following red code: [java] view plaincopy 01./** 02. * Obtain the secret key








































03. * 
04. * @param secretKey
05. * @return
06. * @throws NoSuchAlgorithmException 
07. */ 
08. private SecretKey generateKey(String secretKey) throws NoSuchAlgorithmException{ 
09. <span style="color: rgb(255, 0 , 0);">SecureRandom secureRandom = new SecureRandom(secretKey.getBytes()); //Mainly code here 
10.</span>              
11. //Generate a KeyGenerator object for our chosen DES algorithm 
12. KeyGenerator kg = null; 
13. try { 
14. kg = KeyGenerator.getInstance(DES_ALGORITHM); 
15. } catch (NoSuchAlgorithmException e) { 
16. } 
17. kg.init(secureRandom); 
18. //kg.init(56, secureRandom); 
19.         
20. // Generate the key 
21. return kg.generateKey(); 
22. } 

The SecureRandom implementation follows the internal state of the operating system itself, unless the caller is calling getInstance method, and then call the setSeed method; this implementation generates the same key every time on windows, but is different on solaris or some linux systems. For a detailed introduction to the SecureRandom class, see http://yangzb.iteye.com/blog/325264



Solution

Method 1: Red the red part of the original generateKey method as follows:



[java] view plaincopy
01./**
02. * get secret key
03. * 
04. * @param secretKey
05. * @return
06. * @throws NoSuchAlgorithmException 
07. */ 
08. private SecretKey generateKey(String secretKey) throws NoSuchAlgorithmException{ 
09. <span style="color: rgb(255, 0, 0);"><span><code class="comments">//Prevent random key generation under linux</code></span> 
10. SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); 
11. secureRandom.setSeed(secretKey.getBytes()); 
12./span>       
13. // Generate a KeyGenerator object for our chosen DES algorithm 
14. KeyGenerator kg = null; 
15. try { 
16. kg = KeyGenerator.getInstance(DES_ALGORITHM); 
17. } catch (NoSuchAlgorithmException e) { 
18. } 
19. kg.init(secureRandom); 
20. //kg.init(56, secureRandom); 
21 .     
22. // Generate key 
23. return kg.generateKey(); 
24.} 


Method 2: Instead of using SecureRandom to generate SecretKey, use SecretKeyFactory; reimplement the method generateKey, the code is as follows



[java] view plaincopy
01./**
02. * Get the key
03. * 
04. * @param secretKey
05. * @ return
06. * @throws NoSuchAlgorithmException 
07. * @throws InvalidKeyException 
08. * @throws InvalidKeySpecException 
09. */ 
10. private SecretKey generateKey(String secretKey) throws NoSuchAlgorithmException,InvalidKeyException,InvalidKeySpecException{ 
11.     
12. SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( DES_ALGORITHM); 
13. DESKeySpec keySpec = new DESKeySpec(secretKey.getBytes()); 
14. keyFactory.generateSecret(keySpec); 
15. return keyFactory.generateSecret(keySpec); 
16.} 


Solution 2:

javax.crypto.IllegalBlockSizeException: last block incomplete in decry

Admin
March 12, 2013 Celebrity Quote: Laziness is a special style of attitude towards labor. It is characterized by being difficult to get involved in the work and easy to leave the work - MRMY


Problem has recently


implemented an Android AES encryption and decryption function, but the time of decryption is abnormal.


javax.crypto.IllegalBlockSizeException: last block incomplete in decryption


org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:711) at javax.crypto.Cipher.doFinal(Cipher.java:100)


estimated problem is the time of transmission Because the encoding causes data loss , the


solution


encrypts the ciphertext encrypted by AES and then performs the overall base64 encryption. When decoding, it first decrypts the base64 and then AES decryption, so as to ensure the correctness of the received data and will not be missing.


However, the Base64 encryption and decryption that comes with android is used, but an error is reported. (I don't know why)


Then I googled it and wrote the Base64 encrypted object class itself.





package com.example.testandroid;

import java.io.ByteArrayOutputStream;

public class Base64Util {
    private static final char[] base64EncodeChars = new char[] { ""A"", ""B"", ""C"", ""D"", ""E"", ""F"", ""G"", ""H"", ""I"", ""J"", ""K"", ""L"", ""M"", ""N"", ""O"", ""P"", ""Q"", ""R"", ""S"", ""T"", ""U"", ""V"", ""W"", ""X"", ""Y"", ""Z"", ""a"", ""b"", ""c"", ""d"", ""e"", ""f"", ""g"", ""h"", ""i"", ""j"", ""k"", ""l"", ""m"", ""n"", ""o"", ""p"", ""q"", ""r"", ""s"", ""t"", ""u"", ""v"", ""w"", ""x"", ""y"", ""z"", ""0"", ""1"", ""2"", ""3"", ""4"", ""5"", ""6"", ""7"", ""8"", ""9"", ""+"", ""/"" };

   private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 , -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, - 1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2 , 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43 , 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };

   private Base64Util() {
    }

   /**
     * encode byte array as character String
     *
     * @param data
     */
    public static String encode(byte[] data) {
        StringBuffer sb = new StringBuffer();
        int len = data.length;
        int i = 0;
        int b1, b2, b3;

       while (i < len) {
            b1 = data[i++] & 0 xff;
            if (i == len) {
                sb.append(base64EncodeChars[b1 >>> 2]);
                sb.append(base64EncodeChars[(b1 & 0 x3) << 4]);
                sb.append("==");
                break;
            }
            b2 = data[i++] & 0 xff;
            if (i == len) {
                sb.append(base64EncodeChars[b1 >>> 2]);
                sb.append(base64EncodeChars[((b1 & 0 x03) << 4) | ((b2 & 0 xf0) >>> 4)]);
                sb.append(base64EncodeChars[(b2 & 0 x0f) << 2]);
                sb.append("=");
                break;
            }
            b3 = data[i++] & 0 xff;
            sb.append(base64EncodeChars[b1 >>> 2]);
            sb.append(base64EncodeChars[((b1 & 0 x03) << 4) | ((b2 & 0 xf0) >>> 4)]);
            sb.append(base64EncodeChars[((b2 & 0 x0f) << 2) | ((b3 & 0 xc0) >>> 6)]);
            sb.append(base64EncodeChars[b3 & 0 x3f]);
        }
        return sb.toString();     public static byte[] decode(String str) {      */      * @param str      *      * Decode base64 string to byte array    /**
    }







        byte[] data = str.getBytes();
        int len = data.length;
        ByteArrayOutputStream buf = new ByteArrayOutputStream(len);
        int i = 0;
        int b1, b2, b3, b4;

       while (i < len) {

           /* b1 */
            do {
                b1 = base64DecodeChars[data[i++]];
            } while (i < len && b1 == -1);
            if (b1 == -1) {
                break;
            }

           /* b2 */
            do {
                b2 = base64DecodeChars[data[i++]];
            } while (i < len && b2 == -1);
            if (b2 == -1) {
                break;
            }
            buf.write((int) ((b1 << 2) | ((b2 & 0 x30) >>> 4)));

           /* b3 */
            do {
                b3 = data[i++];
                if (b3 == 61) {
                    return buf.toByteArray();
                }
                b3 = base64DecodeChars[b3];
            } while (i < len && b3 == -1);
            if (b3 == -1) {
                break;
            }
            buf.write((int) (((b2 & 0 x0f) << 4) | ((b3 & 0 x3c) >>> 2)));

           /* b4 */
            do {
                b4 = data[i++];
                if (b4 == 61) {
                    return buf.toByteArray();
                }
                b4 = base64DecodeChars[b4];
            } while (i < len && b4 == -1);
            if (b4 == -1) {
                break;
            }
            buf.write((int) (((b3 & 0 x03) << 6) | b4));
        }
        return buf.toByteArray();
    }
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326942363&siteId=291194637
ssi