Beispiel #1
0
        /// <summary>
        /// For backwards-compatibility reasons, we support both PEM-encoded private keys *and* raw binary files containing
        /// the private key data
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLoadBinaryPrivateKey() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldLoadBinaryPrivateKey()
        {
            // Given
            SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
            PkiUtils certs             = new PkiUtils();

            File keyFile = _testDirectory.file("certificate");

            assertTrue(keyFile.createNewFile());
            sbyte[] raw = certs.LoadPrivateKey(cert.privateKey()).Encoded;

            using (FileChannel ch = FileChannel.open(keyFile.toPath(), WRITE))
            {
                FileUtils.writeAll(ch, ByteBuffer.wrap(raw));
            }

            // When
            PrivateKey pk = certs.LoadPrivateKey(keyFile);

            // Then
            assertNotNull(pk);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldLoadPEMPrivateKey() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldLoadPEMPrivateKey()
        {
            // Given
            SelfSignedCertificate cert = new SelfSignedCertificate("example.com");
            PkiUtils certs             = new PkiUtils();

            File privateKey = cert.privateKey();

            // When
            PrivateKey pk = certs.LoadPrivateKey(privateKey);

            // Then
            assertNotNull(pk);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCreateASelfSignedCertificate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldCreateASelfSignedCertificate()
        {
            // Given
            PkiUtils sslFactory = new PkiUtils();
            File     cPath      = new File(_testDirectory.directory(), "certificate");
            File     pkPath     = new File(_testDirectory.directory(), "key");

            // When
            sslFactory.CreateSelfSignedCertificate(cPath, pkPath, "myhost");

            // Then
            // Attempt to load certificate
            Certificate[] certificates = sslFactory.LoadCertificates(cPath);
            assertThat(certificates.Length, @is(greaterThan(0)));

            // Attempt to load private key
            PrivateKey pk = sslFactory.LoadPrivateKey(pkPath);

            assertThat(pk, notNullValue());
        }