コード例 #1
0
ファイル: Win32Crypto.cs プロジェクト: vibehammer/RdgFileTool
 bool CryptUnprotectData(ref DataBlob pCipherText,
                         ref string pszDescription,
                         ref DataBlob pEntropy,
                         IntPtr pReserved,
                         ref CryptProtectPromptStruct pPrompt,
                         int dwFlags,
                         ref DataBlob pPlainText);
コード例 #2
0
        private static unsafe bool TryDecryptStringUsingLocalUser(string encryptedString, out string result)
        {
            if (string.IsNullOrEmpty(encryptedString))
            {
                result = string.Empty;
                return(false);
            }

            var optionalEntropy = new DataBlob
            {
                Size = 0
            };
            var promptStruct = new CryptProtectPromptStruct
            {
                Size = 0
            };
            var      byteArray = Convert.FromBase64String(encryptedString);
            DataBlob dataIn;

            dataIn.Size = byteArray.Length;
            var      description = string.Empty;
            DataBlob dataOut     = new DataBlob();

            fixed(byte *bytePtr = byteArray)
            {
                dataIn.Data = (IntPtr)bytePtr;
                if (!Win32Crypto.CryptUnprotectData(ref dataIn, ref description, ref optionalEntropy, (IntPtr)null, ref promptStruct,
                                                    0, ref dataOut))
                {
                    result = string.Empty;
                    return(false);
                }

                var data      = (char *)(void *)dataOut.Data;
                var charArray = new char[dataOut.Size / 2];

                for (var i = 0; i < charArray.Length; ++i)
                {
                    charArray[i] = data[i];
                }
                result = new string(charArray);
                Win32Crypto.LocalFree(dataOut.Data);
                return(true);
            }
        }