Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 public static extern bool CryptGenKey(PSSafeCryptProvHandle hProv,
                                       uint Algid,
                                       uint dwFlags,
                                       ref PSSafeCryptKey phKey);
Ejemplo n.º 5
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;
                    }
                }
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
 public static extern bool CryptDuplicateKey(PSSafeCryptKey hKey,
                                             ref uint pdwReserved,
                                             uint dwFlags,
                                             ref PSSafeCryptKey phKey);
Ejemplo n.º 9
0
 public static extern bool CryptDuplicateKey(
     PSSafeCryptKey hKey,
     ref uint pdwReserved,
     uint dwFlags,
     ref PSSafeCryptKey phKey);
Ejemplo n.º 10
0
 public static extern bool CryptExportKey(PSSafeCryptKey hKey,
     PSSafeCryptKey hExpKey,
     uint dwBlobType,
     uint dwFlags,
     byte[] pbData,
     ref uint pdwDataLen);
Ejemplo n.º 11
0
 public static extern bool CryptDecrypt(PSSafeCryptKey hKey,
     IntPtr hHash,
     [MarshalAsAttribute(UnmanagedType.Bool)] bool Final,
     uint dwFlags,
     byte[] pbData,
     ref int pdwDataLen);
Ejemplo n.º 12
0
		public static bool CryptImportKey(PSSafeCryptProvHandle hProv, byte[] pbData, int dwDataLen, PSSafeCryptKey hPubKey, int dwFlags, ref PSSafeCryptKey phKey)
		{
			return true;
		}
Ejemplo n.º 13
0
		public static bool CryptGenKey(PSSafeCryptProvHandle hProv, int Algid, int dwFlags, ref PSSafeCryptKey phKey)
		{
			return true;
		}
Ejemplo n.º 14
0
		public static bool CryptExportKey(PSSafeCryptKey hKey, PSSafeCryptKey hExpKey, int dwBlobType, int dwFlags, byte[] pbData, ref int pdwDataLen)
		{
			pdwDataLen = pbData.Length;
			return true;
		}
Ejemplo n.º 15
0
		public static bool CryptEncrypt(PSSafeCryptKey hKey, IntPtr hHash, [MarshalAs(UnmanagedType.Bool)] bool Final, int dwFlags, byte[] pbData, ref int pdwDataLen, int dwBufLen)
		{
			pdwDataLen = pbData.Length;
			return true;
		}
Ejemplo n.º 16
0
		public static bool CryptDuplicateKey(PSSafeCryptKey hKey, ref int pdwReserved, int dwFlags, ref PSSafeCryptKey phKey)
		{
			return true;
		}
Ejemplo n.º 17
0
 public static extern bool CryptImportKey(PSSafeCryptProvHandle hProv,
     byte[] pbData,
     int dwDataLen,
     PSSafeCryptKey hPubKey,
     uint dwFlags,
     ref PSSafeCryptKey phKey);
Ejemplo n.º 18
0
 public static extern bool CryptGenKey(
     PSSafeCryptProvHandle hProv,
     uint Algid,
     uint dwFlags,
     ref PSSafeCryptKey phKey);