我试图了解Java java.security.Signature类的功能.如果我计算SHA1消息摘要,然后使用RSA加密该摘要,我得到一个不同的结果,要求Signature类签署相同的东西:
// Generate new key
KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
String plaintext = "This is the message being signed";
// Compute signature
Signature instance = Signature.getInstance("SHA1withRSA");
instance.initSign(privateKey);
instance.update((plaintext).getBytes());
byte[] signature = instance.sign();
// Compute digest
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
byte[] digest = sha1.digest((plaintext).getBytes());
// Encrypt digest
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
byte[] cipherText = cipher.doFinal(digest);
// Display results
System.out.println("Input data: " + plaintext);
System.out.println("Digest: " + bytes2String(digest));
System.out.println("Cipher text: " + bytes2String(cipherText)); …
Run Code Online (Sandbox Code Playgroud) 有没有人知道在分散系统中计算你"信任"另一个用户(他们的声誉)的算法.
像这样的网站使用集中的权限来跟踪信誉点,但是当你不能信任某个权威机构公正地维护这个名单,或者基础设施不存在时,你如何对同行的声誉进行排名呢?
我正在想象类似于PageRank的东西- 我相信我的朋友Alice,她相信她的朋友Bob,因此我对Bob有一些可传递的信任.如果我的另一个朋友卡罗尔也信任鲍勃,那么我对鲍勃的信任增加了.
有没有办法在全球范围内计算,或者每个用户都必须跟踪自己的网络?
我以为你可以'声明'你信任谁,这会给每个人一组相应的传入信任链接,但我觉得这很容易通过创建许多只创建声望点的僵尸用户来实现,比如链接农场搜索结果.这可能是问题的核心:如果谷歌仍然存在人们产生虚假PageRank分数的问题,那么它可能不是一个容易解决的问题:)
这个问题:如何生成随机BigInteger描述了一种实现与BigIntegers的Random.nextInt(int n)相同语义的方法.
我想对BigDecimal和Random.nextDouble()做同样的事情.
上述问题中的一个答案建议创建一个随机的BigInteger,然后用随机比例从中创建一个BigDouble.一个非常快速的实验表明这是一个非常糟糕的主意:)
我的直觉是使用这种方法需要通过类似的方式缩放整数n-log10(R)
,其中n是输出中所需的精度位数,R是随机BigInteger.这应该允许存在正确的位数,以便(例如)1 - > 10 ^ -64和10 ^ 64 - > 1.
还需要正确选择缩放值,使结果落在[0,1]范围内.
有没有人以前做过这个,他们知道结果是否正确分布?有没有更好的方法来实现这一目标?
编辑:感谢@biziclop纠正我对scale参数的理解.以上不是必需的,恒定的比例因子具有期望的效果.
为了以后的参考,我(显然是工作代码)是:
private static BigDecimal newRandomBigDecimal(Random r, int precision) {
BigInteger n = BigInteger.TEN.pow(precision);
return new BigDecimal(newRandomBigInteger(n, r), precision);
}
private static BigInteger newRandomBigInteger(BigInteger n, Random rnd) {
BigInteger r;
do {
r = new BigInteger(n.bitLength(), rnd);
} while (r.compareTo(n) >= 0);
return r;
}
Run Code Online (Sandbox Code Playgroud) 具体来说,我正在尝试使用Monogo Java驱动程序访问MonogoHQ,它在本地工作但在服务器上我得到了
有一些限制,所以当我尝试使用以下方法创建连接时,MongoDb Java驱动程序不起作用:
MongoClient mongoClient = new MongoClient( "mydb.mongohq.com", 10014 );
cryptography ×2
java ×2
bigdecimal ×1
biginteger ×1
encryption ×1
math ×1
mongodb ×1
mongohq ×1
p2p ×1
random ×1
rsa ×1
security ×1
trust ×1