PKCS10Test.java
上传用户:lior1029
上传日期:2013-05-07
资源大小:209k
文件大小:3k
源码类别:

CA认证

开发平台:

Java

  1. package org.bouncycastle.asn1.test;
  2. import java.io.*;
  3. import org.bouncycastle.util.encoders.*;
  4. import org.bouncycastle.util.test.*;
  5. import org.bouncycastle.asn1.*;
  6. import org.bouncycastle.asn1.pkcs.*;
  7. public class PKCS10Test
  8. implements Test
  9. {
  10. byte[] req1 = Base64.decode(
  11. "MIHoMIGTAgEAMC4xDjAMBgNVBAMTBVRlc3QyMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNF"
  12. +   "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlEt31Tzt2MlcOljvacJgzQVhmlMoqAOgqJ9Pgd3Gux"
  13. +   "Z7/WcIlgW4QCB7WZT21O1YoghwBhPDMcNGrHei9kHQkCAwEAAaAAMA0GCSqGSIb3DQEBBQUAA0EA"
  14. +   "NDEI4ecNtJ3uHwGGlitNFq9WxcoZ0djbQJ5hABMotav6gtqlrwKXY2evaIrsNwkJtNdwwH18aQDU"
  15. +   "KCjOuBL38Q==");
  16. byte[] req2 = Base64.decode(
  17.                "MIIB6TCCAVICAQAwgagxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRQwEgYDVQQH"
  18.             +  "EwtTYW50YSBDbGFyYTEMMAoGA1UEChMDQUJCMVEwTwYDVQQLHEhQAAAAAAAAAG8AAAAAAAAAdwAA"
  19.             +  "AAAAAABlAAAAAAAAAHIAAAAAAAAAIAAAAAAAAABUAAAAAAAAABxIAAAAAAAARAAAAAAAAAAxDTAL"
  20.             +  "BgNVBAMTBGJsdWUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANETRZ+6occCOrFxNhfKIp4C"
  21.             +  "mMkxwhBNb7TnnahpbM9O0r4hrBPcfYuL7u9YX/jN0YNUP+/CiT39HhSe/bikaBPDEyNsl988I8vX"
  22.             +  "piEdgxYq/+LTgGHbjRsRYCkPtmzwBbuBldNF8bV7pu0v4UScSsExmGqqDlX1TbPU8KkPU1iTAgMB"
  23.             +  "AAGgADANBgkqhkiG9w0BAQQFAAOBgQAFbrs9qUwh93CtETk7DeUD5HcdCnxauo1bck44snSV6MZV"
  24.             +  "OCIGaYu1501kmhEvAtVVRr6SEHwimfQDDIjnrWwYsEr/DT6tkTZAbfRd3qUu3iKjT0H0vlUZp0hJ"
  25.             +  "66mINtBM84uZFBfoXiWY8M3FuAnGmvy6ah/dYtJorTxLKiGkew==");
  26. public String getName()
  27. {
  28. return "PKCS10";
  29. }
  30. public TestResult pkcs10Test(
  31.         String  testName,
  32.         byte[]  req)
  33. {
  34. try
  35. {
  36. ByteArrayInputStream bIn = new ByteArrayInputStream(req);
  37. DERInputStream dIn = new DERInputStream(bIn);
  38. CertificationRequest r = new CertificationRequest((ASN1Sequence)dIn.readObject());
  39. ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  40. DEROutputStream dOut = new DEROutputStream(bOut);
  41. dOut.writeObject(r.getDERObject());
  42. byte[] bytes = bOut.toByteArray();
  43. if (bytes.length != req.length)
  44. {
  45.          return new SimpleTestResult(false, getName() + ": " + testName + " failed length test");
  46. }
  47. for (int i = 0; i != req.length; i++)
  48. {
  49. if (bytes[i] != req[i])
  50. {
  51. return new SimpleTestResult(false, getName() + ": " + testName + " failed comparison test");
  52. }
  53. }
  54. }
  55. catch (Exception e)
  56. {
  57.          return new SimpleTestResult(false, getName() + ": Exception - " + testName + " " + e.toString());
  58. }
  59.         return new SimpleTestResult(true, getName() + ": Okay");
  60.     }
  61. public TestResult perform()
  62.     {
  63.         TestResult  res = pkcs10Test("basic CR", req1);
  64.         if (!res.isSuccessful())
  65.         {
  66.             return res;
  67.         }
  68.         return pkcs10Test("Universal CR", req2);
  69.     }
  70.     public static void main(
  71.         String[]    args)
  72.     {
  73.         Test    test = new PKCS10Test();
  74.         TestResult  result = test.perform();
  75.         System.out.println(result);
  76.     }
  77. }