package org.voovan.test.tools;

import junit.framework.TestCase;
import org.voovan.tools.Cipher;
import org.voovan.tools.log.Logger;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * 类文字命名
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class CipherUnit extends TestCase{

    public void testCipher() throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchPaddingException {
        Cipher cipher = new Cipher("AES","ECB","PKCS5Padding");
//        cipher.generatPairKey();
        cipher.generateSymmetryKey();
        byte[] msg = cipher.encode("asdfadf".getBytes());
        Logger.simple(new String(msg));
        byte[] msg1 = cipher.decode(msg);
        Logger.simple(new String(msg1));
    }
}

@@ -29,41 +29,8 @@
 s;%0A%0A
-import junit.framework.TestCase;%0A
 impo
@@ -57,16 +57,16 @@
 Cipher;%0A
+
 import o
@@ -92,16 +92,49 @@
 .Logger;
+%0Aimport junit.framework.TestCase;
 %0A%0Aimport
@@ -683,16 +683,31 @@
 ption %7B%0A
+        //%E5%AF%B9%E7%A7%B0%E5%8A%A0%E5%AF%86%0A
         
@@ -766,43 +766,8 @@
 %22);%0A
-//        cipher.generatPairKey();%0A
     
@@ -894,24 +894,24 @@
 ring(msg));%0A
-
         byte
@@ -977,20 +977,295 @@
 ing(msg1));%0A
+%0A%0A        //%E9%9D%9E%E5%AF%B9%E7%A7%B0%E5%8A%A0%E5%AF%86%0A        cipher = new Cipher(%22RSA%22,%22ECB%22,%22PKCS1Padding%22);%0A        cipher.generatPairKey();%0A        msg = cipher.encode(%22asdfadf%22.getBytes());%0A        Logger.simple(new String(msg));%0A        msg1 = cipher.decode(msg);%0A        Logger.simple(new String(msg1));%0A
     %7D%0A%7D%0A

优化 Cipher 测试用例