If you need to supply the unencrypted password to a textfield in order to sign in, then nothing you do before that step can stop malicious users from reading the contents of that textbox. Since there needs to be a point in time where that plaintext string is sent to the textbox.
I think if you have a keylogger you have more important problems than encrypting passwords
To answer your question: It should be possible, but you'd need to dig quite deep into the Windows API for that.
To catch COPY events and encrypt the contents, you could use SetClipboardViewer to get notified of changed to the clipboard. Here is an example on how to do this with C#.
To catch PASTE events and decrypt the contents, you might need to globally hook to WM_PASTE messages.
As a side note: Once a keylogger/trojan/etc. managed to run on your system, it is no longer your system. Encrypting the clipboard or similar techniques don't protect your system, they might just raise the bar for the malware developer to get the information he wants (see Jean-Bernard's answer). Preventing evil code from running on your system in the first place is a much better approach.
If the clipboard information is persisted to the drive then whole disk encryption would do the trick (it sounds like that's the kind of stuff you want to do already anyway based on the question).
But encrypting what's in RAM isn't really an option. At some point the OS and applications read that memory and need to know what to do with it. It has to be unencrypted somewhere in the active hardware of the machine in order to be used.
You could certainly encrypt the data, copy it to the clipboard, and then in another instance of your app, paste it, decrypt it. But this is only useful if the source/destination agree on the encryption. i.e. written by the same guy. In that case, you'd be better off NOT using the clipboard, and setting up some sort of private data channel instead. So while you can do it, it's not practical.
If someone has privileges to install a keylogger that has clipboard access, he most likely has privileges to get the decryption key of the clipboard as well. Cryptography is not a substitute for access control.
发布评论
评论(7)
如果您需要向文本字段提供未加密的密码才能登录,那么在此步骤之前执行的任何操作都无法阻止恶意用户读取该文本框的内容。因为需要有一个时间点将明文字符串发送到文本框。
我认为如果你有一个键盘记录器,你就会遇到比加密密码更重要的问题
If you need to supply the unencrypted password to a textfield in order to sign in, then nothing you do before that step can stop malicious users from reading the contents of that textbox. Since there needs to be a point in time where that plaintext string is sent to the textbox.
I think if you have a keylogger you have more important problems than encrypting passwords
回答你的问题:这应该是可能的,但你需要深入研究 Windows API。
要捕获COPY事件并加密内容,您可以使用
SetClipboardViewer
获取剪贴板更改的通知。 此处是有关如何使用 C# 执行此操作的示例。要捕获PASTE事件并解密内容,您可能需要全局挂钩
WM_PASTE
消息。附注:曾经是键盘记录器/木马等。设法在您的系统上运行,它不再是您的系统。加密剪贴板或类似技术并不能保护您的系统,它们可能只会提高恶意软件开发人员获取他想要的信息的门槛(请参阅 Jean-Bernard 的回答)。首先防止邪恶代码在您的系统上运行是一个更好的方法。
To answer your question: It should be possible, but you'd need to dig quite deep into the Windows API for that.
To catch COPY events and encrypt the contents, you could use
SetClipboardViewer
to get notified of changed to the clipboard. Here is an example on how to do this with C#.To catch PASTE events and decrypt the contents, you might need to globally hook to
WM_PASTE
messages.As a side note: Once a keylogger/trojan/etc. managed to run on your system, it is no longer your system. Encrypting the clipboard or similar techniques don't protect your system, they might just raise the bar for the malware developer to get the information he wants (see Jean-Bernard's answer). Preventing evil code from running on your system in the first place is a much better approach.
如果剪贴板信息保留到驱动器,那么整个磁盘加密就可以解决问题(听起来这就是您根据问题已经想做的事情)。
但加密 RAM 中的内容并不是真正的选择。在某些时候,操作系统和应用程序会读取该内存并需要知道如何处理它。它必须在机器的活动硬件某处未加密才能使用。
If the clipboard information is persisted to the drive then whole disk encryption would do the trick (it sounds like that's the kind of stuff you want to do already anyway based on the question).
But encrypting what's in RAM isn't really an option. At some point the OS and applications read that memory and need to know what to do with it. It has to be unencrypted somewhere in the active hardware of the machine in order to be used.
您当然可以加密数据,将其复制到剪贴板,然后在应用程序的另一个实例中粘贴它,解密它。但这仅在源/目标同意加密时才有用。即由同一个人写的。在这种情况下,您最好不要使用剪贴板,而是设置某种私有数据通道。
因此,虽然你可以做到,但它并不实用。
You could certainly encrypt the data, copy it to the clipboard, and then in another instance of your app, paste it, decrypt it. But this is only useful if the source/destination agree on the encryption. i.e. written by the same guy. In that case, you'd be better off NOT using the clipboard, and setting up some sort of private data channel instead.
So while you can do it, it's not practical.
您可以通过在复制之前加密应用程序的数据来做到这一点,但这实际上取决于您将使用的语言。
并在粘贴上解密,但再次在您的应用程序上解密。您不能对所有系统都这样做;这意味着对您的操作系统进行修改......
You could do that by encrypting your data for your application before the copy, but it really depends on the language you would use.
And decrypt on the paste, but again on your application. You can't do that for all your system; it would mean modifications on your OS...
我正在编写一个实现复制粘贴的应用程序:因此我使用系统 API 从剪贴板读取数据。
如果我无法读取未加密的数据,那么复制粘贴就会被破坏,但如果我可以,那么任何其他已安装的程序(包括键盘记录器)也可以。
I'm writing an application which implements copy-and-paste: therefore I use a system API to read data from the clipboard.
If I can't read unencrypted data then copy-and-paste is broken, but if I can then so could any other installed program (including a keylogger).
如果某人有权安装具有剪贴板访问权限的键盘记录器,那么他很可能也有权获取剪贴板的解密密钥。密码学不能替代访问控制。
If someone has privileges to install a keylogger that has clipboard access, he most likely has privileges to get the decryption key of the clipboard as well. Cryptography is not a substitute for access control.