[英]Using MessageDigest with J2ME Application
I'm unable to use the MessageDigest
API in a J2ME application - it is giving ALERT NoSuchMethodError 我无法在J2ME应用程序中使用MessageDigest
API - 它给出了ALERT NoSuchMethodError
digest() 消化()
My code is 我的代码是
MessageDigest md= MessageDigest.getInstance("SHA-1");
md.update(hashString.getBytes("UTF-8"),0,0);
byte[] digest = null;
md.digest(digest,0,digest.length);
System.out.println("digest of str is "+new String(digest) );
The above code works fine in a Java application, but gives NoSuchMethodError
in J2ME. 上面的代码在Java应用程序中运行良好,但在J2ME中给出了NoSuchMethodError
。
Can I use MessageDigest
in J2ME? 我可以在J2ME中使用MessageDigest
吗? If yes , please tell me how. 如果是 ,请告诉我如何。
java.security.MessageDigest is not generally part of J2ME, so it's not directly available. java.security.MessageDigest通常不是J2ME的一部分,因此它不能直接使用。
There are some J2ME devices that implement JSR 177 , which would allow you to use MessageDigest
. 有些 J2ME设备实现了JSR 177 ,它允许您使用MessageDigest
。
Or, you could try an open source SHA1 implementation, such as this one . 或者,您可以尝试使用开源SHA1实现, 例如此实现。
Another alternative would be to use the BouncyCastle library, and use it to implement SHA1 digests for J2ME . 另一种方法是使用BouncyCastle库,并使用它来实现J2ME的SHA1摘要 。
If you use BouncyCastle, make sure to get one of the releases (.jar or source code) that's designed for J2ME . 如果您使用BouncyCastle,请确保获取为J2ME设计的其中一个版本(.jar或源代码)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.