【发布时间】:2012-11-12 21:13:11
【问题描述】:
我正在实现一个使用大量数字的加密算法,所以在制作 Java 应用程序时我必须使用 BigInteger 类。
但是,当我尝试在 android 应用程序中实现相同的构造函数时
public BigInteger(int bitLength,int certainty,Random rnd),
没有生成随机的 BigInteger(同样的整数一次又一次地生成 35879 :P)。在一个简单的 java Application 中成功生成一个随机的 BigInteger。
供参考,
http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#constructor_detail
另外,请告诉我,如果我导入 java.util.* 形式的东西,它是否可以在任何 android 应用程序中工作?
如果 Android 不支持 BigInteger 或存在与支持的类似的任何其他类,请制作您的 cmets ???
这里使用 systemoutprintln() 方法将相应的字符串打印到布局中。
这是一个代码供您参考,
public class keyGenerator {
/**
* @param args the command line arguments
*/
static Vector check = new Vector();
static protected BigInteger p= new BigInteger("161");
static protected BigInteger q= new BigInteger("47");
static protected Random s =new Random();
static protected BigInteger n = new BigInteger("1");
static protected BigInteger trails;
static protected BigInteger lambda ;
static protected BigInteger nsq = new BigInteger("1");
static protected BigInteger g = new BigInteger("1");
static protected BigInteger temp = new BigInteger("1");
static protected long timetkn;
static protected View myview;
static protected String[] printarray = new String[1000];
static protected int ii=0;
static protected int maxbit;
private static BigInteger two = new BigInteger("2");
public keyGenerator() {
// Activity activity = new Activity();
// et.append("Second Part!!");
// EditText et = (EditText)activity.findViewById(R.string.second);
// et.append("Working");
long keyStart = SystemClock.uptimeMillis();
p = new BigInteger(7,1,s);
Systemoutprintln("Assumed p :" +p.toString());
/* while(!isPrime(p) && ( (p.compareTo(two)==1) || (p.compareTo(two))==0) )
{
p = new BigInteger(7,1,s);
Systemoutprintln(p.toString());
}*/
Systemoutprintln("Assumed q :" +p.toString());
q = new BigInteger(7,1,s);
【问题讨论】:
-
您应该关注
Random对象(BigDecimal 只是包装它)来检查它的行为。 -
您应该使用
SecureRandom进行加密。 -
您在哪种设备上获得这些结果?也许在模拟器上?
-
@owlstead 是 Galaxy Nexus S 4.1 手机
标签: java android encryption private-key