开发者

General Statement for SecureRandom return Error - Java

I've searched throughout different forums and now I am finally putting my question as I can't find specific answer.

I am writing security protocol for SunSPOT Sensors as my final year Project.

I wish to generate a 128 bit Key which can be hashed later on, through my search on web I come across that best method to generate the random keys is SecureRandom.

I am trying to implement the general statement to see how it works so that I can use it further according to my requirement

SecureRandom gen = SecureRandom.getInstance("SHA1WITHECDSA");

above statment I have used with "SHA1PRNG", "MD5ECDSA" and "ECDSAWithSHA1Signature" as soon as I complete Statement and put semicolon it return this Error

method getInstance in class com.sun.spot.security.implementation.SecureRandom cannot be applied to given types

required: byte found: java.lang.String

I have added the Jar file respectively to the build.xml and into the build.properties ; also the imported the algori开发者_如何学Pythonthm into the program.

Thanks for reading

and any help is much appriciated

Thankyou Every One who have tried to help.

Hash (Hasnain)


Why not just say "SecureRandom()" and let the system pick the algorithm? Here is an explicit example:

import java.security.SecureRandom;

public class Rando {
    public static void main(String[] args) {
        System.out.println(new SecureRandom().nextFloat());
    }

}


Are you using the correct class? You should be using java.security.SecureRandom. Also, SHA1WITHECDSA, MD5ECDSA, and ECDSAWithSHA1Signature are nonsensical as SecureRandom instances.


Sounds to me as if you're calling a method that requires a byte as argument, but you are supplying a String.


The error is referring to the class com.sun.spot.security.implementation.SecureRandom. You should presumably be using java.security.SecureRandom (it is this class that has the getInstance method that takes a String).

You probably have an incorrect import statement.


Instance required for secure random in SunSPOT java application is as follow

SecureRandom gen; gen = SecureRandom.getInstance(SecureRandom.ALG_SECURE_RANDOM);

I would like to Thank Everyone who put their effort to resolve this error.

Thanks once again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜