Esempio n. 1
0
        public static mx509.X509Certificate OpenSslX509ToMonoX509(ox509.X509Certificate cert)
        {
            BIO bio = BIO.MemoryBuffer(true);

            cert.Write(bio);
            byte[] raw = new byte[bio.BytesPending];
            bio.Read(raw, raw.Length);
            bio.Dispose();
            return(new mx509.X509Certificate(raw));
        }
Esempio n. 2
0
        public static ox509.X509Certificate MonoX509ToOpenSsl(mx509.X509Certificate cert)
        {
            BIO bio = BIO.MemoryBuffer(true);

            bio.Write(cert.RawData);
            var ocert = ox509.X509Certificate.FromDER(bio);

            bio.Dispose();
            return(ocert);
        }
Esempio n. 3
0
 /// <summary>
 /// 公钥加密
 /// </summary>
 public static string PublicEncrypt(string publicKey, string text, Encoding encoding, int padding)
 {
     byte[] textBytes = encoding.GetBytes(text);
     using (BIO bio = new BIO(publicKey))
     {
         using (OpenSSL.Crypto.RSA rsa = OpenSSL.Crypto.RSA.FromPublicKey(bio))
         {
             textBytes = rsa.PublicEncrypt(textBytes, (OpenSSL.Crypto.RSA.Padding)padding);
             rsa.Dispose();
         }
         bio.Dispose();
     }
     return(Convert.ToBase64String(textBytes));
 }