Ejemplo n.º 1
0
        /// <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)
        {
            var thunk = new PasswordThunk(callback, arg);
            var ptr   = Native.PEM_read_bio_RSAPrivateKey(bio.Handle, IntPtr.Zero, thunk.Callback, IntPtr.Zero);

            return(new RSA(Native.ExpectNonNull(ptr), true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calls PEM_read_bio_PrivateKey()
        /// </summary>
        /// <param name="bio"></param>
        /// <param name="handler"></param>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static CryptoKey FromPrivateKey(BIO bio, PasswordHandler handler, object arg)
        {
            PasswordThunk thunk = new PasswordThunk(handler, arg);
            IntPtr        ptr   = Native.ExpectNonNull(Native.PEM_read_bio_PrivateKey(
                                                           bio.Handle,
                                                           IntPtr.Zero,
                                                           thunk.Callback,
                                                           IntPtr.Zero
                                                           ));

            return(new CryptoKey(ptr, true));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calls PEM_write_bio_DSAPrivateKey()
        /// </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)
        {
            var thunk = new PasswordThunk(passwd, arg);

            Native.ExpectSuccess(Native.PEM_write_bio_DSAPrivateKey(
                                     bio.Handle,
                                     ptr,
                                     enc == null ? IntPtr.Zero : enc.Handle,
                                     null,
                                     0,
                                     thunk.Callback,
                                     IntPtr.Zero));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calls PEM_write_bio_PKCS8PrivateKey
        /// </summary>
        /// <param name="bp"></param>
        /// <param name="cipher"></param>
        /// <param name="handler"></param>
        /// <param name="arg"></param>
        public void WritePrivateKey(BIO bp, Cipher cipher, PasswordHandler handler, object arg)
        {
            PasswordThunk thunk = new PasswordThunk(handler, null);

            Native.ExpectSuccess(Native.PEM_write_bio_PKCS8PrivateKey(bp.Handle, this.ptr, cipher.Handle, IntPtr.Zero, 0, thunk.Callback, IntPtr.Zero));
        }