internal void ImportPublicKeyFromBase64EncodedString(string publicKey) { byte[] pbData = Convert.FromBase64String(publicKey); bool flag = PSCryptoNativeUtils.CryptImportKey(this.hProv, pbData, pbData.Length, PSSafeCryptKey.Zero, 0, ref this.hRSAKey); this.CheckStatus(flag); }
internal void ImportSessionKeyFromBase64EncodedString(string sessionKey) { byte[] pbData = Convert.FromBase64String(sessionKey); bool flag = PSCryptoNativeUtils.CryptImportKey(this.hProv, pbData, pbData.Length, this.hRSAKey, 0, ref this.hSessionKey); this.CheckStatus(flag); this.canEncrypt = true; }
private void CheckStatus(bool value) { if (!value) { int lastError = PSCryptoNativeUtils.GetLastError(); StringBuilder message = new StringBuilder(new Win32Exception((int)lastError).Message); throw new PSCryptoException(lastError, message); } }
internal string GetPublicKeyAsBase64EncodedString() { uint pdwDataLen = 0; this.CheckStatus(PSCryptoNativeUtils.CryptExportKey(this.hRSAKey, PSSafeCryptKey.Zero, 6U, 0U, (byte[])null, ref pdwDataLen)); byte[] numArray = new byte[(IntPtr)pdwDataLen]; this.CheckStatus(PSCryptoNativeUtils.CryptExportKey(this.hRSAKey, PSSafeCryptKey.Zero, 6U, 0U, numArray, ref pdwDataLen)); return(Convert.ToBase64String(numArray, Base64FormattingOptions.None)); }
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(); }
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 string GetPublicKeyAsBase64EncodedString() { int pdwDataLen = 0; bool flag = PSCryptoNativeUtils.CryptExportKey(this.hRSAKey, PSSafeCryptKey.Zero, 6, 0, null, ref pdwDataLen); this.CheckStatus(flag); byte[] pbData = new byte[pdwDataLen]; flag = PSCryptoNativeUtils.CryptExportKey(this.hRSAKey, PSSafeCryptKey.Zero, 6, 0, pbData, ref pdwDataLen); this.CheckStatus(flag); return(Convert.ToBase64String(pbData, Base64FormattingOptions.None)); }
internal string GenerateSessionKeyAndSafeExport() { this.CheckStatus(PSCryptoNativeUtils.CryptGenKey(this.hProv, 26128U, 16777221U, ref this.hSessionKey)); uint pdwDataLen = 0; this.CheckStatus(PSCryptoNativeUtils.CryptExportKey(this.hSessionKey, this.hRSAKey, 1U, 0U, (byte[])null, ref pdwDataLen)); byte[] numArray = new byte[(IntPtr)pdwDataLen]; this.CheckStatus(PSCryptoNativeUtils.CryptExportKey(this.hSessionKey, this.hRSAKey, 1U, 0U, numArray, ref pdwDataLen)); this.canEncrypt = true; return(Convert.ToBase64String(numArray, Base64FormattingOptions.None)); }
internal string SafeExportSessionKey() { this.GenerateSessionKey(); int pdwDataLen = 0; bool flag = PSCryptoNativeUtils.CryptExportKey(this.hSessionKey, this.hRSAKey, 1, 0, null, ref pdwDataLen); this.CheckStatus(flag); byte[] pbData = new byte[pdwDataLen]; flag = PSCryptoNativeUtils.CryptExportKey(this.hSessionKey, this.hRSAKey, 1, 0, pbData, ref pdwDataLen); this.CheckStatus(flag); this.canEncrypt = true; return(Convert.ToBase64String(pbData, Base64FormattingOptions.None)); }
internal void GenerateSessionKey() { if (!this.sessionKeyGenerated) { lock (syncObject) { if (!this.sessionKeyGenerated) { bool flag = PSCryptoNativeUtils.CryptGenKey(this.hProv, 0x6610, 0x1000005, ref this.hSessionKey); this.CheckStatus(flag); this.sessionKeyGenerated = true; this.canEncrypt = true; } } } }
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; }
internal byte[] DecryptWithSessionKey(byte[] data) { byte[] pbData = new byte[data.Length]; Array.Copy((Array)data, 0, (Array)pbData, 0, data.Length); int length = pbData.Length; if (!PSCryptoNativeUtils.CryptDecrypt(this.hSessionKey, IntPtr.Zero, true, 0U, pbData, ref length)) { pbData = new byte[length]; Array.Copy((Array)data, 0, (Array)pbData, 0, data.Length); this.CheckStatus(PSCryptoNativeUtils.CryptDecrypt(this.hSessionKey, IntPtr.Zero, true, 0U, pbData, ref length)); } byte[] numArray = new byte[length]; Array.Copy((Array)pbData, 0, (Array)numArray, 0, length); for (int index = 0; index < pbData.Length; ++index) { pbData[index] = (byte)0; } return(numArray); }
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; }
internal byte[] DecryptWithSessionKey(byte[] data) { byte[] destinationArray = new byte[data.Length]; Array.Copy(data, 0, destinationArray, 0, data.Length); int length = destinationArray.Length; if (!PSCryptoNativeUtils.CryptDecrypt(this.hSessionKey, IntPtr.Zero, true, 0, destinationArray, ref length)) { destinationArray = new byte[length]; Array.Copy(data, 0, destinationArray, 0, data.Length); bool flag = PSCryptoNativeUtils.CryptDecrypt(this.hSessionKey, IntPtr.Zero, true, 0, destinationArray, ref length); this.CheckStatus(flag); } byte[] buffer2 = new byte[length]; Array.Copy(destinationArray, 0, buffer2, 0, length); for (int i = 0; i < destinationArray.Length; i++) { destinationArray[i] = 0; } return(buffer2); }
protected override bool ReleaseHandle() => PSCryptoNativeUtils.CryptDestroyKey(this.handle);
protected override bool ReleaseHandle() { return(PSCryptoNativeUtils.CryptReleaseContext(base.handle, 0)); }
protected override bool ReleaseHandle() => PSCryptoNativeUtils.CryptReleaseContext(this.handle, 0U);
protected override bool ReleaseHandle() { return(PSCryptoNativeUtils.CryptDestroyKey(base.handle)); }