Well, it would happen if MessageDigest.getInstance() throw NoSuchAlgorithmException because you're printing out the exception but then carrying on regardless However, it's actually happening because of this: private static final char HEX_CHARS = null and then this: chars2 * I = HEX_CHARS(bufi & 0xF0) >>> 4 I suspect you're not actually running the code you've got in front of you - on my machine at least, the NPE correctly points to line 24, the line including HEX_CHARS To fix: private static final char HEX_CHARS = "0123456789ABCDEF".toCharArray().
Well, it would happen if MessageDigest.getInstance() throw NoSuchAlgorithmException - because you're printing out the exception but then carrying on regardless. However, it's actually happening because of this: private static final char HEX_CHARS = null; and then this: chars2 * I = HEX_CHARS(bufi & 0xF0) >>> 4; I suspect you're not actually running the code you've got in front of you - on my machine at least, the NPE correctly points to line 24, the line including HEX_CHARS. To fix: private static final char HEX_CHARS = "0123456789ABCDEF".toCharArray().
Ok thanks! I just took the code from stackoverflow. Com/questions/4895523/java-string-to-sha1, the last example and implemented it.
And my eclipse auto-fixed the Hex-Chars with private static final char HEX_CHARS = null; I replaced that line with your line. And now I recieve the right result. But I wonder if this code is optimal for a SHA1 hash-function?
– Woho87 Mar 1 at 18:32 @Woho87: It's okay, as far as I'm aware - although you should definitely do something about that catch block. You should probably throw a RuntimeException. – Jon Skeet Mar 1 at 18:36 Do you mean wrap try{} with whole method body and then catch(Exception e){ e.printStackTrace();}?
– Woho87 Mar 1 at 18:44 @Woho87: No, I mean get rid of e.printStackTrace(); in the current code and replace it with throw new RuntimeException(e);. Swallowing an exception and just pretending it didn't happen is almost never the right approach. – Jon Skeet Mar 1 at 18:46 ok Jon Skeet, thank you very much really appreciete it!
– Woho87 Mar 1 at 18:51.
Your HEX_CHARS variable is never set to anything besides null.
Try putting something other than null in HEX_CHARS.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.