1 7 package se.anatom.ejbca.util; 8 9 import java.security.cert.X509Certificate ; 10 11 import junit.framework.TestCase; 12 13 import org.apache.log4j.Logger; 14 import org.bouncycastle.util.encoders.Hex; 15 import org.ejbca.util.Base64; 16 import org.ejbca.util.CertTools; 17 18 23 public class TestHex extends TestCase { 24 private static final Logger log = Logger.getLogger(TestHex.class); 25 29 public TestHex(String name) { 30 super(name); 31 } 32 33 protected void setUp() throws Exception { 34 log.debug(">setUp()"); 35 CertTools.installBCProvider(); 36 log.debug("<setUp()"); 37 } 38 39 protected void tearDown() throws Exception { 40 } 41 42 public void test01HexSmall() throws Exception { 43 byte[] certBytes = Base64.decode(testcert_oneline.getBytes()); 45 assertNotNull(certBytes); 46 X509Certificate cert = CertTools.getCertfromByteArray(certBytes); 48 assertNotNull(cert); 49 byte[] hexBytes = Hex.decode(hexCert.getBytes()); 50 assertEquals(new String (Base64.encode(certBytes)),new String (Base64.encode(hexBytes))); 51 X509Certificate cert1 = CertTools.getCertfromByteArray(hexBytes); 52 assertEquals(cert.getSubjectDN().toString(), cert1.getSubjectDN().toString()); 53 byte[] hexBytes2 = Hex.encode(cert1.getEncoded()); 54 assertEquals(new String (hexBytes2), hexCert); 55 56 } 57 58 private static String testcert_oneline = ("MIIDATCCAmqgAwIBAgIIczEoghAwc3EwDQYJKoZIhvcNAQEFBQAwLzEPMA0GA1UE" 59 + "AxMGVGVzdENBMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNFMB4XDTAzMDky" 60 + "NDA2NDgwNFoXDTA1MDkyMzA2NTgwNFowMzEQMA4GA1UEAxMHcDEydGVzdDESMBAG" 61 + "A1UEChMJUHJpbWVUZXN0MQswCQYDVQQGEwJTRTCBnTANBgkqhkiG9w0BAQEFAAOB" 62 + "iwAwgYcCgYEAnPAtfpU63/0h6InBmesN8FYS47hMvq/sliSBOMU0VqzlNNXuhD8a" 63 + "3FypGfnPXvjJP5YX9ORu1xAfTNao2sSHLtrkNJQBv6jCRIMYbjjo84UFab2qhhaJ" 64 + "wqJgkQNKu2LHy5gFUztxD8JIuFPoayp1n9JL/gqFDv6k81UnDGmHeFcCARGjggEi" 65 + "MIIBHjAPBgNVHRMBAf8EBTADAQEAMA8GA1UdDwEB/wQFAwMHoAAwOwYDVR0lBDQw" 66 + "MgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDBAYIKwYBBQUHAwUGCCsGAQUF" 67 + "BwMHMB0GA1UdDgQWBBTnT1aQ9I0Ud4OEfNJkSOgJSrsIoDAfBgNVHSMEGDAWgBRj" 68 + "e/R2qFQkjqV0pXdEpvReD1eSUTAiBgNVHREEGzAZoBcGCisGAQQBgjcUAgOgCQwH" 69 + "Zm9vQGZvbzASBgNVHSAECzAJMAcGBSkBAQEBMEUGA1UdHwQ+MDwwOqA4oDaGNGh0" 70 + "dHA6Ly8xMjcuMC4wLjE6ODA4MC9lamJjYS93ZWJkaXN0L2NlcnRkaXN0P2NtZD1j" 71 + "cmwwDQYJKoZIhvcNAQEFBQADgYEAU4CCcLoSUDGXJAOO9hGhvxQiwjGD2rVKCLR4" 72 + "emox1mlQ5rgO9sSel6jHkwceaq4A55+qXAjQVsuy76UJnc8ncYX8f98uSYKcjxo/" 73 + "ifn1eHMbL8dGLd5bc2GNBZkmhFIEoDvbfn9jo7phlS8iyvF2YhC4eso8Xb+T7+BZ" 74 + "QUOBOvc="); 75 76 private static String hexCert = "308203013082026aa00302010202087331288210307371300d06092a864886f70d0101050500302f310f300d06035504031306546573744341310f300d060355040a1306416e61546f6d310b3009060355040613025345301e170d3033303932343036343830345a170d3035303932333036353830345a30333110300e060355040313077031327465737431123010060355040a13095072696d6554657374310b300906035504061302534530819d300d06092a864886f70d010101050003818b00308187028181009cf02d7e953adffd21e889c199eb0df05612e3b84cbeafec96248138c53456ace534d5ee843f1adc5ca919f9cf5ef8c93f9617f4e46ed7101f4cd6a8dac4872edae4349401bfa8c24483186e38e8f3850569bdaa861689c2a26091034abb62c7cb9805533b710fc248b853e86b2a759fd24bfe0a850efea4f355270c69877857020111a38201223082011e300f0603551d130101ff04053003010100300f0603551d0f0101ff0405030307a000303b0603551d250434303206082b0601050507030106082b0601050507030206082b0601050507030406082b0601050507030506082b06010505070307301d0603551d0e04160414e74f5690f48d147783847cd26448e8094abb08a0301f0603551d23041830168014637bf476a854248ea574a57744a6f45e0f57925130220603551d11041b3019a017060a2b060104018237140203a0090c07666f6f40666f6f30120603551d20040b300930070605290101010130450603551d1f043e303c303aa038a0368634687474703a2f2f3132372e302e302e313a383038302f656a6263612f776562646973742f63657274646973743f636d643d63726c300d06092a864886f70d01010505000381810053808270ba1250319724038ef611a1bf1422c23183dab54a08b4787a6a31d66950e6b80ef6c49e97a8c793071e6aae00e79faa5c08d056cbb2efa5099dcf277185fc7fdf2e49829c8f1a3f89f9f578731b2fc7462dde5b73618d059926845204a03bdb7e7f63a3ba61952f22caf1766210b87aca3c5dbf93efe0594143813af7"; 77 } 78 | Popular Tags |