예제 #1
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.hSessionKey != null)
         {
             if (!this.hSessionKey.IsInvalid)
             {
                 this.hSessionKey.Dispose();
             }
             this.hSessionKey = null;
         }
         if ((_hStaticRSAKey == null) && (this.hRSAKey != null))
         {
             if (!this.hRSAKey.IsInvalid)
             {
                 this.hRSAKey.Dispose();
             }
             this.hRSAKey = null;
         }
         if ((_hStaticProv == null) && (this.hProv != null))
         {
             if (!this.hProv.IsInvalid)
             {
                 this.hProv.Dispose();
             }
             this.hProv = null;
         }
     }
 }
예제 #2
0
 public static extern bool CryptImportKey(
     PSSafeCryptProvHandle hProv,
     byte[] pbData,
     int dwDataLen,
     PSSafeCryptKey hPubKey,
     uint dwFlags,
     ref PSSafeCryptKey phKey);
 private PSRSACryptoServiceProvider(bool serverMode)
 {
     if (serverMode)
     {
         this.hProv = new PSSafeCryptProvHandle();
         this.CheckStatus(PSCryptoNativeUtils.CryptAcquireContext(ref this.hProv, (string)null, (string)null, 24U, 4026531840U));
         this.hRSAKey = new PSSafeCryptKey();
     }
     this.hSessionKey = new PSSafeCryptKey();
 }
예제 #4
0
        private PSRSACryptoServiceProvider(bool serverMode)
        {
            if (serverMode)
            {
                this.hProv = new PSSafeCryptProvHandle();
				bool flag = PSCryptoNativeUtils.CryptAcquireContext(ref this.hProv, null, null, 0x18, Int32.MaxValue); // (0xf0000000).ToInt32());
                this.CheckStatus(flag);
                this.hRSAKey = new PSSafeCryptKey();
            }
            this.hSessionKey = new PSSafeCryptKey();
        }
예제 #5
0
 private PSRSACryptoServiceProvider(bool serverMode)
 {
     if (serverMode)
     {
         this.hProv = new PSSafeCryptProvHandle();
         bool flag = PSCryptoNativeUtils.CryptAcquireContext(ref this.hProv, null, null, 0x18, Int32.MaxValue);                 // (0xf0000000).ToInt32());
         this.CheckStatus(flag);
         this.hRSAKey = new PSSafeCryptKey();
     }
     this.hSessionKey = new PSSafeCryptKey();
 }
 internal void GenerateKeyPair()
 {
     if (!PSRSACryptoServiceProvider.keyGenerated)
     {
         lock (PSRSACryptoServiceProvider.syncObject)
         {
             if (!PSRSACryptoServiceProvider.keyGenerated)
             {
                 PSRSACryptoServiceProvider._hStaticProv = new PSSafeCryptProvHandle();
                 this.CheckStatus(PSCryptoNativeUtils.CryptAcquireContext(ref PSRSACryptoServiceProvider._hStaticProv, (string)null, (string)null, 24U, 4026531840U));
                 PSRSACryptoServiceProvider._hStaticRSAKey = new PSSafeCryptKey();
                 this.CheckStatus(PSCryptoNativeUtils.CryptGenKey(PSRSACryptoServiceProvider._hStaticProv, 1U, 134217729U, ref PSRSACryptoServiceProvider._hStaticRSAKey));
                 PSRSACryptoServiceProvider.keyGenerated = true;
             }
         }
     }
     this.hProv   = PSRSACryptoServiceProvider._hStaticProv;
     this.hRSAKey = PSRSACryptoServiceProvider._hStaticRSAKey;
 }
예제 #7
0
 internal void GenerateKeyPair()
 {
     if (!keyPairGenerated)
     {
         lock (syncObject)
         {
             if (!keyPairGenerated)
             {
                 _hStaticProv = new PSSafeCryptProvHandle();
                 bool flag = PSCryptoNativeUtils.CryptAcquireContext(ref _hStaticProv, null, null, 0x18, (0xf0000000).ToInt32());
                 this.CheckStatus(flag);
                 _hStaticRSAKey = new PSSafeCryptKey();
                 flag           = PSCryptoNativeUtils.CryptGenKey(_hStaticProv, 1, 0x8000001, ref _hStaticRSAKey);
                 this.CheckStatus(flag);
                 keyPairGenerated = true;
             }
         }
     }
     this.hProv   = _hStaticProv;
     this.hRSAKey = _hStaticRSAKey;
 }
예제 #8
0
        /// <summary>
        /// Generates key pair in a thread safe manner
        /// the first time when required
        /// </summary>
        internal void GenerateKeyPair()
        {
            if (!s_keyPairGenerated)
            {
                lock (s_syncObject)
                {
                    if (!s_keyPairGenerated)
                    {
                        s_hStaticProv = new PSSafeCryptProvHandle();
                        // We need PROV_RSA_AES to support AES-256 symmetric key
                        // encryption. PROV_RSA_FULL supports only RC2 and RC4
                        bool ret = PSCryptoNativeUtils.CryptAcquireContext(ref s_hStaticProv,
                            null,
                            null,
                            PSCryptoNativeUtils.PROV_RSA_AES,
                            PSCryptoNativeUtils.CRYPT_VERIFYCONTEXT);

                        CheckStatus(ret);

                        s_hStaticRSAKey = new PSSafeCryptKey();
                        ret = PSCryptoNativeUtils.CryptGenKey(s_hStaticProv,
                            PSCryptoNativeUtils.AT_KEYEXCHANGE,
                            0x08000000 | PSCryptoNativeUtils.CRYPT_EXPORTABLE,  // key length -> 2048
                            ref s_hStaticRSAKey);

                        CheckStatus(ret);

                        // key needs to be generated once
                        s_keyPairGenerated = true;
                    }
                }
            }

            _hProv = s_hStaticProv;
            _hRSAKey = s_hStaticRSAKey;
        }
예제 #9
0
        /// <summary>
        /// Private constructor
        /// </summary>
        /// <param name="serverMode">indicates if this service
        /// provider is operating in server mode</param>
        private PSRSACryptoServiceProvider(bool serverMode)
        {
            if (serverMode)
            {
                _hProv = new PSSafeCryptProvHandle();

                // We need PROV_RSA_AES to support AES-256 symmetric key
                // encryption. PROV_RSA_FULL supports only RC2 and RC4
                bool ret = PSCryptoNativeUtils.CryptAcquireContext(ref _hProv,
                    null,
                    null,
                    PSCryptoNativeUtils.PROV_RSA_AES,
                    PSCryptoNativeUtils.CRYPT_VERIFYCONTEXT);

                CheckStatus(ret);

                _hRSAKey = new PSSafeCryptKey();
            }
            _hSessionKey = new PSSafeCryptKey();
        }
예제 #10
0
 public static extern bool CryptImportKey(PSSafeCryptProvHandle hProv,
     byte[] pbData,
     int dwDataLen,
     PSSafeCryptKey hPubKey,
     uint dwFlags,
     ref PSSafeCryptKey phKey);
예제 #11
0
 public static extern bool CryptAcquireContext(
     ref PSSafeCryptProvHandle phProv,
     [MarshalAs(UnmanagedType.LPWStr), In] string szContainer,
     [MarshalAs(UnmanagedType.LPWStr), In] string szProvider,
     uint dwProvType,
     uint dwFlags);
예제 #12
0
 public static bool CryptImportKey(PSSafeCryptProvHandle hProv, byte[] pbData, int dwDataLen, PSSafeCryptKey hPubKey, int dwFlags, ref PSSafeCryptKey phKey)
 {
     return(true);
 }
예제 #13
0
 public static bool CryptGenKey(PSSafeCryptProvHandle hProv, int Algid, int dwFlags, ref PSSafeCryptKey phKey)
 {
     return(true);
 }
예제 #14
0
        /*
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptAcquireContext(ref PSSafeCryptProvHandle phProv, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainer, [In, MarshalAs(UnmanagedType.LPWStr)] string szProvider, int dwProvType, int dwFlags);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptDecrypt(PSSafeCryptKey hKey, IntPtr hHash, [MarshalAs(UnmanagedType.Bool)] bool Final, int dwFlags, byte[] pbData, ref int pdwDataLen);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptDestroyKey(IntPtr hKey);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptDuplicateKey(PSSafeCryptKey hKey, ref int pdwReserved, int dwFlags, ref PSSafeCryptKey phKey);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptEncrypt(PSSafeCryptKey hKey, IntPtr hHash, [MarshalAs(UnmanagedType.Bool)] bool Final, int dwFlags, byte[] pbData, ref int pdwDataLen, int dwBufLen);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptExportKey(PSSafeCryptKey hKey, PSSafeCryptKey hExpKey, int dwBlobType, int dwFlags, byte[] pbData, ref int pdwDataLen);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptGenKey(PSSafeCryptProvHandle hProv, int Algid, int dwFlags, ref PSSafeCryptKey phKey);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptImportKey(PSSafeCryptProvHandle hProv, byte[] pbData, int dwDataLen, PSSafeCryptKey hPubKey, int dwFlags, ref PSSafeCryptKey phKey);
         * [return: MarshalAs(UnmanagedType.Bool)]
         * [DllImport("advapi32.dll")]
         * public static extern bool CryptReleaseContext(IntPtr hProv, int dwFlags);
         * [DllImport("kernel32.dll")]
         * public static extern int GetLastError();
         *
         */


        public static bool CryptAcquireContext(ref PSSafeCryptProvHandle phProv, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainer, [In, MarshalAs(UnmanagedType.LPWStr)] string szProvider, int dwProvType, int dwFlags)
        {
            return(true);
        }
예제 #15
0
        //[SecurityPermission(SecurityAction.Demand, UnmanagedCode=true)]
        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (null != _hSessionKey)
                {
                    if (!_hSessionKey.IsInvalid)
                    {
                        _hSessionKey.Dispose();
                    }
                    _hSessionKey = null;
                }

                // we need to dismiss the provider and key
                // only if the static members are not allocated
                // since otherwise, these are just references 
                // to the static members

                if (null == s_hStaticRSAKey)
                {
                    if (null != _hRSAKey)
                    {
                        if (!_hRSAKey.IsInvalid)
                        {
                            _hRSAKey.Dispose();
                        }
                        _hRSAKey = null;
                    }
                }

                if (null == s_hStaticProv)
                {
                    if (null != _hProv)
                    {
                        if (!_hProv.IsInvalid)
                        {
                            _hProv.Dispose();
                        }
                        _hProv = null;
                    }
                }
            }
        }
예제 #16
0
 public static extern bool CryptGenKey(PSSafeCryptProvHandle hProv,
                                       uint Algid,
                                       uint dwFlags,
                                       ref PSSafeCryptKey phKey);
예제 #17
0
		/*
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptAcquireContext(ref PSSafeCryptProvHandle phProv, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainer, [In, MarshalAs(UnmanagedType.LPWStr)] string szProvider, int dwProvType, int dwFlags);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptDecrypt(PSSafeCryptKey hKey, IntPtr hHash, [MarshalAs(UnmanagedType.Bool)] bool Final, int dwFlags, byte[] pbData, ref int pdwDataLen);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptDestroyKey(IntPtr hKey);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptDuplicateKey(PSSafeCryptKey hKey, ref int pdwReserved, int dwFlags, ref PSSafeCryptKey phKey);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptEncrypt(PSSafeCryptKey hKey, IntPtr hHash, [MarshalAs(UnmanagedType.Bool)] bool Final, int dwFlags, byte[] pbData, ref int pdwDataLen, int dwBufLen);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptExportKey(PSSafeCryptKey hKey, PSSafeCryptKey hExpKey, int dwBlobType, int dwFlags, byte[] pbData, ref int pdwDataLen);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptGenKey(PSSafeCryptProvHandle hProv, int Algid, int dwFlags, ref PSSafeCryptKey phKey);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptImportKey(PSSafeCryptProvHandle hProv, byte[] pbData, int dwDataLen, PSSafeCryptKey hPubKey, int dwFlags, ref PSSafeCryptKey phKey);
        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("advapi32.dll")]
        public static extern bool CryptReleaseContext(IntPtr hProv, int dwFlags);
        [DllImport("kernel32.dll")]
        public static extern int GetLastError();

		*/


		public static bool CryptAcquireContext(ref PSSafeCryptProvHandle phProv, [In, MarshalAs(UnmanagedType.LPWStr)] string szContainer, [In, MarshalAs(UnmanagedType.LPWStr)] string szProvider, int dwProvType, int dwFlags)
		{
			return true;
		}
예제 #18
0
		public static bool CryptGenKey(PSSafeCryptProvHandle hProv, int Algid, int dwFlags, ref PSSafeCryptKey phKey)
		{
			return true;
		}
예제 #19
0
		public static bool CryptImportKey(PSSafeCryptProvHandle hProv, byte[] pbData, int dwDataLen, PSSafeCryptKey hPubKey, int dwFlags, ref PSSafeCryptKey phKey)
		{
			return true;
		}
예제 #20
0
 internal void GenerateKeyPair()
 {
     if (!keyPairGenerated)
     {
         lock (syncObject)
         {
             if (!keyPairGenerated)
             {
                 _hStaticProv = new PSSafeCryptProvHandle();
                 bool flag = PSCryptoNativeUtils.CryptAcquireContext(ref _hStaticProv, null, null, 0x18, (0xf0000000).ToInt32());
                 this.CheckStatus(flag);
                 _hStaticRSAKey = new PSSafeCryptKey();
                 flag = PSCryptoNativeUtils.CryptGenKey(_hStaticProv, 1, 0x8000001, ref _hStaticRSAKey);
                 this.CheckStatus(flag);
                 keyPairGenerated = true;
             }
         }
     }
     this.hProv = _hStaticProv;
     this.hRSAKey = _hStaticRSAKey;
 }
예제 #21
0
 public static extern bool CryptAcquireContext(ref PSSafeCryptProvHandle phProv,
     [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string szContainer,
     [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string szProvider,
     uint dwProvType,
     uint dwFlags);
예제 #22
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.hSessionKey != null)
         {
             if (!this.hSessionKey.IsInvalid)
             {
                 this.hSessionKey.Dispose();
             }
             this.hSessionKey = null;
         }
         if ((_hStaticRSAKey == null) && (this.hRSAKey != null))
         {
             if (!this.hRSAKey.IsInvalid)
             {
                 this.hRSAKey.Dispose();
             }
             this.hRSAKey = null;
         }
         if ((_hStaticProv == null) && (this.hProv != null))
         {
             if (!this.hProv.IsInvalid)
             {
                 this.hProv.Dispose();
             }
             this.hProv = null;
         }
     }
 }
예제 #23
0
 public static extern bool CryptGenKey(
     PSSafeCryptProvHandle hProv,
     uint Algid,
     uint dwFlags,
     ref PSSafeCryptKey phKey);