Package fr.jayasoft.crypto

Source Code of fr.jayasoft.crypto.KeysFromBytesTest

/*
* This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
* Copyright Jayasoft 2005 - All rights reserved
*
* #SNAPSHOT#
*/
package fr.jayasoft.crypto;

import junit.framework.TestCase;
import fr.jayasoft.commons.util.HexUtil;
import fr.jayasoft.crypto.decoder.Decoder;
import fr.jayasoft.crypto.encoder.Encoder;
import fr.jayasoft.crypto.keys.KeyGenerator;
import fr.jayasoft.crypto.keys.KeyHelper;

public class KeysFromBytesTest extends TestCase {
    public void testImplementations() {
        doTestAlgo(CryptoFactory.NONE);
        doTestAlgo(CryptoFactory.DES);
        doTestAlgo(CryptoFactory.BLOWFISH);
        doTestAlgo(CryptoFactory.RSA);
    }
   
    public void doTestAlgo(String algo) {
        System.out.println("testing: " + algo);
        Crypto c = CryptoFactory.get(algo);
        KeyGenerator kg = c.getKeyGenerator();
        byte[] decodingKey = HexUtil.hexStringToByteArray(HexUtil.byteArrayToHexString(KeyHelper.getBytes(kg.getDecodingKey())));
        byte[] encodingKey = HexUtil.hexStringToByteArray(HexUtil.byteArrayToHexString(KeyHelper.getBytes(kg.getEncodingKey())));
       
        Object decKey = kg.getDecodingKey(decodingKey);
        Object encKey = kg.getEncodingKey(encodingKey);
       
       
        Encoder e = c.newEncoder(encKey);
        Decoder d = c.newDecoder(decKey);
       
        String msg = "just a simple message";
        assertEquals(msg, d.decodeAsString(e.encode(msg)));
    }
   
    public void simpleTest() {
        String encStrKey = "30819F300D06092A864886F70D010101050003818D0030818902818100C17778A5EB23626E08B12D19D68C91F88C78471ECCF2E418708594E95A813C48AB4B40D670483383F780F54AA29C2C2A2E78FB08B07EB5D8B762C669FE46F059ECBB650246780AE04F96C4B9AAF105CF57DEB044F26F1E5D87B8D56955F859203E5320654858CC866197E734D0B268C5549A0975C06AF7BC7FD35D86A6B4A4750203010001";
        String decStrKey = "30820276020100300D06092A864886F70D0101010500048202603082025C02010002818100C17778A5EB23626E08B12D19D68C91F88C78471ECCF2E418708594E95A813C48AB4B40D670483383F780F54AA29C2C2A2E78FB08B07EB5D8B762C669FE46F059ECBB650246780AE04F96C4B9AAF105CF57DEB044F26F1E5D87B8D56955F859203E5320654858CC866197E734D0B268C5549A0975C06AF7BC7FD35D86A6B4A4750203010001028180722494AFFF7D0EF3B079280CD8827314DB7B932A5EECE71A6C38C3D4B1AB11F025EFEE3F165BE2D8F74BC46CD667A1BEF950337BBAF5E74007626581DF9DE6EB7E6E93748BDA4D5ADBAEFA7FC5BAE0CF733BD4CCE70C6050FE3F00C126EF323C37655DF0DB793EF06850CE608146888A1A54544C1ABB2E7925805FEA0B026D41024100FD3695C5CC0289929E9B1A7378D018DF4FDC8BA3543BF6B2494B9228305C260A90FEF73F47D685EDA0ACE7214A6ED050BBE59EF139646E3AAB92444270AD181D024100C3988DB233698370E172CC758511DA5EE72923AFB1DE4E93B2514005C2A73FA0DCAEF9DFDA115CA20DDB5EE0A3A74E59E8AE6312B21E53076C826C64FDBC7E3902406792C74AA3FB39B8AE85B5191C86CA55B5BDF9A4325560C06678B1ED1C72E4E09794A31FD04BB07695AD83D13B37FE9FB76BE24ABB76181C898787C241829C05024018B571D8FC23AD261A64DD2D4F6524F7EE2DC54351ADEAB13FCA81D2F8771653A4ED39C5AC8F9AEB21E2FF8653463460A9433662CB3B87739DA2903CE5CCE509024100F22F9F28C078C59055EC694C5D30C66A89FA4F57AC44202BC4379752C7CF9982F6E99D0F6AAD2AC48CA5C4EFE1A83F9F3F9FB6EF6ECA704BEF5D9811F0712AF7";
        Crypto c = CryptoFactory.get(CryptoFactory.RSA);
        KeyGenerator kg = c.getKeyGenerator();
       
        kg.getDecodingKey(HexUtil.hexStringToByteArray(decStrKey));
        kg.getEncodingKey(HexUtil.hexStringToByteArray(encStrKey));
    }
   
    public static void main(String[] args) {
        new KeysFromBytesTest().simpleTest();
    }
}
TOP

Related Classes of fr.jayasoft.crypto.KeysFromBytesTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.