I am sorry in Advance as I know this question is too general but I am new to this so it is difficult for me to make this question more specific.
I am working on an application in which the client has some security issues. He don't want users able to print screen or copy (ctrl+c the program's data. Now when I started to work on this I found that when these key strokes his the OS copies the data in its buffer. Now I have tried to make checks that whenever user hits the key strokes of ctrl+c or printscreen then my application suddenly flush the buffer (or cache whatever we say this). Now my question is
1: How can I flush the window's buffer using Java? which class API should I check for this? (As I searched alot but I didn't find the way :( so it is the time for SO experts)
2: Would this flushBuffer code work for all OS? or Would I need to make separate checks for Windows/Linux/Mac.
Thanks
-
3Assuming you've managed to do this, then how do you prevent the user pulling up his smartphone / camera and taking picture of his computer screen :) ?gerrytan– gerrytan2013-03-28 05:34:07 +00:00Commented Mar 28, 2013 at 5:34
-
1Don't forget you'd also need to handle programs like screen recorders (Gimps, camstudio, etc), screenshot helper programs (Snipping Tool) and so on. I recall a program long ago, Realplayer, that seemed impossible to print screen because whenever I tried it, the video simply wasn't in the screenshot and the program showed a black screen instead. Apparently what it did was write directly to video memory - you could try that, but be aware that it is bypassable (by changing video settings in windows).Patashu– Patashu2013-03-28 05:35:21 +00:00Commented Mar 28, 2013 at 5:35
-
Basically you cannot do this reliably. If your client is happy with something that works for regular users but not to more advanced (or, like mentioned by gerrytan, anyone using a camera), only then there is something that is even remotely possible. Note also that since you would be clearing the copy buffer shared by all programs, you're in danger of breaking other software.eis– eis2013-03-28 05:41:31 +00:00Commented Mar 28, 2013 at 5:41
-
@eis understood :) but what is way to clear the buffer?Despicable– Despicable2013-03-28 05:49:04 +00:00Commented Mar 28, 2013 at 5:49
-
@despicable added as an answereis– eis2013-03-28 06:04:22 +00:00Commented Mar 28, 2013 at 6:04
4 Answers
To disable copy+paste from any components in your app you can do (taken from Disabling 'paste' in a jTextfield)
textComponent.setTransferHandler(null);
But anything beyond that will be a hack. You can listen to print screen globally using jnativehook and then maybe somehow black out your window. I don't know, paranoia is a tricky thing.
Comments
You can clear the copy paste buffer like explained here:
- http://docs.oracle.com/javase/tutorial/uiswing/dnd/textpaste.html
- http://docs.oracle.com/javase/tutorial/uiswing/dnd/listpaste.html
just have empty text and copy that to buffer.
Beyond that, there's not that much reliable things you can do.
Code would be something like:
Action action = new DefaultEditorKit.CopyAction();
action.actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
Edit: for a web app, see this answer, using clipboard jquery plugin this way.
5 Comments
well according to requirement/security issue, it would be wrong design to clear memory (after allowing data to write in it). Better you override the key-strokes. like ctrl/alt+(any key) or printscr
to override key behaviors, you need to implement KeyListener. once you define custom behaviour for that key, it will not allow the default actions (like copy/cut..)
3 Comments
How about this alternative approach:
- Assuming your program uses Swing UI, only show the sensitive data when user focuses on the window, when user focus to another window / program, make the data invisible
- Assuming you're using windows, you can disable print screen using group policy like mentioned in this post
- Use copy-paste prevention mechanism suggested by other posters
To be honest I haven't tried this and I'm not sure if it'll work. It might also be OS dependant
2 Comments
when you press ctrl+c, consumes the input and does nothing How can I do this? I am searching the way for this functionality