public void ConvertToBouncyCastleObjectTest() { X509Certificate2 dotNetCert = null; BCX509.X509Certificate bcCert = null; // From ByteArray try { bcCert = CertUtils.ToBouncyCastleObject((byte[])null); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } bcCert = CertUtils.ToBouncyCastleObject(_derCert); Assert.IsTrue(bcCert != null); bcCert = CertUtils.ToBouncyCastleObject(_pemCert); Assert.IsTrue(bcCert != null); try { bcCert = CertUtils.ToBouncyCastleObject(_noCert); Assert.IsTrue(bcCert == null); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is CryptographicException); } // From DotNetObject try { bcCert = CertUtils.ToBouncyCastleObject((X509Certificate2)null); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } dotNetCert = CertUtils.ToDotNetObject(_derCert); bcCert = CertUtils.ToBouncyCastleObject(dotNetCert); Assert.IsTrue(bcCert != null); dotNetCert = CertUtils.ToDotNetObject(_pemCert); bcCert = CertUtils.ToBouncyCastleObject(dotNetCert); Assert.IsTrue(bcCert != null); }
public void ConvertToDerEncodedByteArray() { byte[] derCert = null; X509Certificate2 dotNetCert = null; BCX509.X509Certificate bcCert = null; // From BouncyCastleObject try { derCert = CertUtils.ToDerEncodedByteArray((BCX509.X509Certificate)null); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } bcCert = CertUtils.ToBouncyCastleObject(_derCert); derCert = CertUtils.ToDerEncodedByteArray(bcCert); Assert.IsTrue(Convert.ToBase64String(derCert) == Convert.ToBase64String(_derCert)); bcCert = CertUtils.ToBouncyCastleObject(_pemCert); derCert = CertUtils.ToDerEncodedByteArray(bcCert); Assert.IsTrue(Convert.ToBase64String(derCert) == Convert.ToBase64String(_derCert)); // From DotNetObject try { derCert = CertUtils.ToDerEncodedByteArray((X509Certificate2)null); Assert.Fail("Exception expected but not thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } dotNetCert = CertUtils.ToDotNetObject(_derCert); derCert = CertUtils.ToDerEncodedByteArray(dotNetCert); Assert.IsTrue(Convert.ToBase64String(derCert) == Convert.ToBase64String(_derCert)); dotNetCert = CertUtils.ToDotNetObject(_pemCert); derCert = CertUtils.ToDerEncodedByteArray(dotNetCert); Assert.IsTrue(Convert.ToBase64String(derCert) == Convert.ToBase64String(_derCert)); }