本文整理汇总了C#中OpenSSL.Core.BIO类的典型用法代码示例。如果您正苦于以下问题:C# BIO类的具体用法?C# BIO怎么用?C# BIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BIO类属于OpenSSL.Core命名空间,在下文中一共展示了BIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPKCS12Certificate
public static X509Certificate LoadPKCS12Certificate(string resource, string password)
{
using (var bio = new BIO(LoadBytes(resource)))
{
return X509Certificate.FromPKCS12(bio, password);
}
}
示例2: PKCS12
/// <summary>
/// Calls d2i_PKCS12_bio() and then PKCS12_parse()
/// </summary>
/// <param name="bio"></param>
/// <param name="password"></param>
public PKCS12(BIO bio, string password)
: base(Native.ExpectNonNull(Native.d2i_PKCS12_bio(bio.Handle, IntPtr.Zero)), true)
{
IntPtr cert;
IntPtr pkey;
IntPtr cacerts;
// Parse the PKCS12 object and get privatekey, cert, cacerts if available
Native.ExpectSuccess(Native.PKCS12_parse(this.ptr, password, out pkey, out cert, out cacerts));
if (cert != IntPtr.Zero)
{
this.certificate = new X509Certificate(cert, true);
if (pkey != IntPtr.Zero)
{
this.privateKey = new CryptoKey(pkey, true);
// We have a private key, assign it to the cert
this.certificate.PrivateKey = this.privateKey.CopyRef();
}
}
if (cacerts != IntPtr.Zero)
{
this.caCertificates = new Core.Stack<X509Certificate>(cacerts, true);
}
}
示例3: LoadX509Chain
public static X509Chain LoadX509Chain(string resource)
{
using (var bio = new BIO(LoadBytes(resource)))
{
return new X509Chain(bio);
}
}
示例4: CanLoadFromPKCS7_DER
public void CanLoadFromPKCS7_DER()
{
using (BIO bio = new BIO(LoadBytes(Resources.CaChainP7c))) {
using (X509Certificate cert = X509Certificate.FromPKCS7_DER(bio)) {
TestCert(cert, "CN=Root", "CN=Root", 1234);
}
}
}
示例5: CanLoadFromPKCS7_PEM
public void CanLoadFromPKCS7_PEM()
{
using (BIO bio = new BIO(LoadString(Resources.CaChainP7cPem))) {
using (X509Certificate cert = X509Certificate.FromPKCS7_PEM(bio)) {
TestCert(cert, "CN=Root", "CN=Root", 1234);
}
}
}
示例6: CanLoadFromPEM
public void CanLoadFromPEM()
{
using (BIO bio = new BIO(LoadString(Resources.CaCrt))) {
using (X509Certificate cert = new X509Certificate(bio)) {
TestCert(cert, "CN=Root", "CN=Root", 1234);
}
}
}
示例7: CanLoadFromDER
public void CanLoadFromDER()
{
using (var bio = new BIO(Util.LoadBytes(Resources.CaDer)))
{
using (var cert = X509Certificate.FromDER(bio))
{
TestCert(cert, "CN=Root", "CN=Root", 1234);
}
}
}
示例8: Print
/// <summary>
/// Prints the LongName of this cipher.
/// </summary>
/// <param name="bio"></param>
public override void Print(BIO bio)
{
bio.Write(this.LongName);
}
示例9: WritePrivateKey
/// <summary>
/// Calls PEM_write_bio_RSAPrivateKey()
/// </summary>
/// <param name="bio"></param>
/// <param name="enc"></param>
/// <param name="passwd"></param>
/// <param name="arg"></param>
public void WritePrivateKey(BIO bio, Cipher enc, PasswordHandler passwd, object arg)
{
PasswordThunk thunk = new PasswordThunk(passwd, arg);
Native.ExpectSuccess(Native.PEM_write_bio_RSAPrivateKey(
bio.Handle,
this.ptr,
enc == null ? IntPtr.Zero : enc.Handle,
null,
0,
thunk.Callback,
IntPtr.Zero));
}
示例10: FromPrivateKey
/// <summary>
/// Calls PEM_read_bio_RSAPrivateKey()
/// </summary>
/// <param name="bio"></param>
/// <param name="callback"></param>
/// <param name="arg"></param>
/// <returns></returns>
public static RSA FromPrivateKey(BIO bio, PasswordHandler callback, object arg)
{
PasswordThunk thunk = new PasswordThunk(callback, arg);
IntPtr ptr = Native.PEM_read_bio_RSAPrivateKey(bio.Handle, IntPtr.Zero, thunk.Callback, IntPtr.Zero);
return new RSA(Native.ExpectNonNull(ptr), true);
}
示例11: FromPrivateKey
/// <summary>
/// Returns PEM_read_bio_DSAPrivateKey()
/// </summary>
/// <param name="bio"></param>
/// <returns></returns>
public static DSA FromPrivateKey(BIO bio)
{
return new DSA(Native.ExpectNonNull(Native.PEM_read_bio_DSAPrivateKey(bio.Handle, IntPtr.Zero, null, IntPtr.Zero)), true);
}
示例12: DtlsAssociation
/// <summary>Create a DtlsFilter.</summary>
/// <param name="key">A CryptoKey initialized by the OpenSSL.NET library.</param>
/// <param name="cert">The path to the certificate to use.</param>
/// <param name="ca_cert">The path to the ca certificate to use.</param>
/// <param name="client">Use client initialization parameters.</param>
public DtlsAssociation(ISender sender, CertificateHandler ch, PType ptype,
Ssl ssl, bool client) : base(sender, ch)
{
_ip = new IdentifierPair();
PType = ptype;
_ssl = ssl;
_client = client;
_ssl.SetReadAhead(1);
// Buggy SSL versions have issue with compression and dtls
_ssl.SetOptions((int) SslOptions.SSL_OP_NO_COMPRESSION);
if(client) {
_ssl.SetConnectState();
} else {
_ssl.SetAcceptState();
}
// The ssl object will take control
_read = BIO.MemoryBuffer(false);
_read.NonBlocking = true;
_write = BIO.MemoryBuffer(false);
_write.NonBlocking = true;
_ssl.SetBIO(_read, _write);
_ssl.DoHandshake();
_buffer = new byte[Int16.MaxValue];
_buffer_sync = new object();
_fe_lock = 0;
}
示例13: Verify
/// <summary>
/// Calls EVP_VerifyFinal()
/// </summary>
/// <param name="md"></param>
/// <param name="bio"></param>
/// <param name="sig"></param>
/// <param name="pkey"></param>
/// <returns></returns>
public static bool Verify(MessageDigest md, BIO bio, byte[] sig, CryptoKey pkey)
{
BIO bmd = BIO.MessageDigest(md);
bmd.Push(bio);
while (true)
{
ArraySegment<byte> bytes = bmd.ReadBytes(1024 * 4);
if (bytes.Count == 0)
break;
}
MessageDigestContext ctx = new MessageDigestContext(bmd);
int ret = Native.ExpectSuccess(Native.EVP_VerifyFinal(ctx.Handle, sig, (uint)sig.Length, pkey.Handle));
return ret == 1;
}
示例14: CanCreatePKCS12
public void CanCreatePKCS12() {
using (BIO bio = new BIO(LoadBytes(Resources.ServerPfx))) {
using (var pfx = new PKCS12(bio, password)) {
using (var new_pfx = new PKCS12(password, pfx.PrivateKey, pfx.Certificate, pfx.CACertificates)) {
TestCert(new_pfx.Certificate, "CN=localhost", "CN=Root", 1235);
}
}
}
}
示例15: CanLoadFromPCKS12
public void CanLoadFromPCKS12()
{
using (BIO bio = new BIO(LoadBytes(Resources.ServerPfx))) {
using (X509Certificate cert = X509Certificate.FromPKCS12(bio, password)) {
TestCert(cert, "CN=localhost", "CN=Root", 1235);
}
}
}