FAQ Database Discussion Community


Hashing String (SHA-256) in an ActionListener class

java,exception,event-listener,checked-exceptions
I want to use the following code in an ActionListener class. MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(key.getBytes("UTF-8")); BigInteger HashValue = new BigInteger(javax.xml.bind.DatatypeConverter.printHexBinary(hash).toLowerCase(), 16); String HashValueString = HashValue.toString(); But the "SHA-256" and "UTF-8" can't be imported in any way. When I do this in a console program, I can...

Javascript Event Listener at Interval

javascript,intervals,event-listener
I'm listening for motion data on devices, using the ondevicemotion API. For example: window.ondevicemotion = function(event) { // do something with the event } I want to run this function when I call it; however, because it is based on an event, it triggers when the event does (which, depending...

How to execute a JS code block on pressing ESC key?

javascript,keycode,event-listener
I want to execute a JS code when user presses ESC key. Please help me how can I do this? My current code is not working. I don't know where I'm doing wrong? I'm just a beginner so please help me out.. function hideModalKeyPress(e) { if(e.keyCode == 27) { document.getElementsByClassName('modalOverlay')[0].style.visibility...