本文整理了Java中java.math.BigInteger.toString()
方法的一些代码示例,展示了BigInteger.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.toString()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:toString
[英]Returns a string representation of this BigInteger in decimal form.
[中]以十进制形式返回此BigInteger的字符串表示形式。
代码示例来源:origin: stackoverflow.com
import java.security.SecureRandom;
import java.math.BigInteger;
public final class SessionIdentifierGenerator {
private SecureRandom random = new SecureRandom();
public String nextSessionId() {
return new BigInteger(130, random).toString(32);
}
}
代码示例来源:origin: stackoverflow.com
String plaintext = "your text here";
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
代码示例来源:origin: cucumber/cucumber-jvm
private String checksum(String gherkin) {
return new BigInteger(1, md5.digest(gherkin.getBytes(UTF8))).toString(16);
}
代码示例来源:origin: stackoverflow.com
BigInteger bi = new BigInteger("76292708057987193002565060032465481997");
System.out.println(bi.toString(16));
代码示例来源:origin: konsoletyper/teavm
private static void testBigInteger() {
System.out.println("Running BigInteger benchmark");
BigInteger result = BigInteger.ONE;
for (int j = 0; j < 100; ++j) {
long start = System.currentTimeMillis();
for (int k = 0; k < 5000; ++k) {
BigInteger a = BigInteger.ZERO;
BigInteger b = BigInteger.ONE;
for (int i = 0; i < 1000; ++i) {
BigInteger c = a.add(b);
a = b;
b = c;
}
result = a;
}
long end = System.currentTimeMillis();
System.out.println("Operation took " + (end - start) + " milliseconds");
}
System.out.println(result.toString());
}
代码示例来源:origin: Curzibn/Luban
@Override
public String rename(String filePath) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(filePath.getBytes());
return new BigInteger(1, md.digest()).toString(32);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
})
代码示例来源:origin: aa112901/remusic
public static void main3(String[] args) {
String key = "7b104953fb112826";
String pubKey = "010001";
String m = "157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607";
try {
String k = reverse(key);
String keyTo16 = toHex(k, "GBK");
// System.out.println(new BigInteger(keyTo16, 16));
// new BigInteger(keyTo16, 16) 字符串转为16进制数字,
// pow(Integer.valueOf(pubKey, 16)) 得到次方的值
//remainder 取余数
String c = (new BigInteger(keyTo16, 16).pow(Integer.valueOf(pubKey, 16))).remainder(new BigInteger(m)) + "";
//转为16进制表示
System.out.println(new BigInteger(c).toString(16));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
代码示例来源:origin: mpusher/mpush
private static void test() {
Pair<RSAPublicKey, RSAPrivateKey> pair = RSAUtils.genKeyPair(RAS_KEY_SIZE);
//生成公钥和私钥
RSAPublicKey publicKey = pair.key;
RSAPrivateKey privateKey = pair.value;
//模
String modulus = publicKey.getModulus().toString();
//公钥指数
String public_exponent = publicKey.getPublicExponent().toString();
//私钥指数
String private_exponent = privateKey.getPrivateExponent().toString();
//明文
byte[] ming = "123456789".getBytes(Constants.UTF_8);
System.out.println("明文:" + new String(ming, Constants.UTF_8));
//使用模和指数生成公钥和私钥
RSAPrivateKey priKey = RSAUtils.getPrivateKey(modulus, private_exponent);
RSAPublicKey pubKey = RSAUtils.getPublicKey(modulus, public_exponent);
System.out.println("privateKey=" + priKey);
System.out.println("publicKey=" + pubKey);
//加密后的密文
byte[] mi = RSAUtils.encryptByPublicKey(ming, pubKey);
System.out.println("密文:" + new String(mi, Constants.UTF_8));
//解密后的明文
ming = RSAUtils.decryptByPrivateKey(mi, priKey);
System.out.println("解密:" + new String(ming, Constants.UTF_8));
}
代码示例来源:origin: stackoverflow.com
Random random = new SecureRandom();
String token = new BigInteger(130, random).toString(32);
代码示例来源:origin: pockethub/PocketHub
private static String digest(final String value) {
if (MD5 == null) {
return null;
}
byte[] bytes;
try {
bytes = value.getBytes(CHARSET);
} catch (UnsupportedEncodingException e) {
return null;
}
synchronized (MD5) {
MD5.reset();
bytes = MD5.digest(bytes);
}
String hashed = new BigInteger(1, bytes).toString(16);
int padding = HASH_LENGTH - hashed.length();
if (padding == 0) {
return hashed;
}
char[] zeros = new char[padding];
Arrays.fill(zeros, '0');
return String.valueOf(zeros) + hashed;
}
代码示例来源:origin: redisson/redisson
private static String calcClassSign(String name) {
try {
Class<?> clazz = Class.forName(name);
ByteArrayOutputStream result = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(result);
outputStream.writeObject(clazz);
outputStream.close();
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(result.toByteArray());
return new BigInteger(1, crypt.digest()).toString(16);
} catch (Exception e) {
throw new IllegalStateException("Can't calculate sign of " + name, e);
}
}
代码示例来源:origin: aa112901/remusic
RSAPublicKeySpec rsaPubKS = new RSAPublicKeySpec(new BigInteger(big1, 16), new BigInteger(big2, 16));
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPublicKey publicKey = (RSAPublicKey) kf.generatePublic(rsaPubKS);
String modulus = publicKey.getModulus().toString();
String public_exponent = publicKey.getPublicExponent().toString();
System.err.println(modulus);
System.err.println(public_exponent);
System.err.println(mi);
代码示例来源:origin: ethereum/ethereumj
@Test
public void blockTest() {
String rlp = "f90498f90490f90217a0887405e8cf98cfdbbf5ab4521d45a0803e397af61852d94dc46ca077787088bfa0d6d234f05ac90931822b7b6f244cef81" +
"83e5dd3080483273d6c2fcc02399216294ee0250c19ad59305b2bdb61f34b45b72fe37154fa0caa558a47a66b975426c6b963c46bb83d969787cfedc09fd2cab8ab83155568da07c970ab3f2004e2aa0" +
"7d7b3dda348a3a4f8f4ab98b3504c46c1ffae09ef5bd23a077007d3a4c7c88823e9f80b1ba48ec74f88f40e9ec9c5036235fc320fe8a29ffb90100000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008311fc6782" +
"02868508cc8cac48825208845682c3479ad983010302844765746887676f312e352e318777696e646f7773a020269a7f434e365b012659d1b190aa1586c22d7bbf0ed7fad73ca7d2b60f623c8841c814" +
"3ae845fb3df867f8656e850ba43b7400830fffff9431e2e1ed11951c7091dfba62cd4b7145e947219c4d801ba0ad82686ee482723f88d9760b773e7b8234f126271e53369b928af0cbab302baea04fe3" +
"dd2e0dbcc5d53123fe49f3515f0844c7e4c6dd3752f0cf916f4bb5cbe80bf9020af90207a08752c2c47c96537cf695bdecc9696a8ea35b6bfdc1389a134b47ad63fea38c2ca01dcc4de8dec75d7aab85" +
"b567b6ccd41ad312451b948a7413f0a142fd40d493479450b8f981ce93fd5b81b844409169148428400bf3a05bff1dc620da4d3a123f8e08536434071281d64fc106105fb3bc94b6b1b8913ba0b59542" +
"42bb4483396ae474b02651b40d4a9d61ab99a7455e57ef31f2688bdf81a03068c58706501d3059f40a5366debf4bf1cad48439d19f00154076c5d96c26d6b90100000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
"008311f7ea8202848508d329637f825208845682c3438acccccccccccccccccccca0216ef6369d46fe0ad70d2b7f9aa0785f33cbb8894733859136b5143c0ed8b09f88bc45a9ac8c1cea67842b0113c6";
NewBlockMessage msg = new NewBlockMessage(Hex.decode(rlp));
Block b = msg.getBlock();
System.out.println(b);
System.out.println(msg.getDifficultyAsBigInt().toString(16));
}
代码示例来源:origin: apache/kafka
public String secureRandomString() {
return new BigInteger(130, random).toString(Character.MAX_RADIX);
}
代码示例来源:origin: spotbugs/spotbugs
public @CheckForNull
String getHash(String sourceFile) {
StringBuilder rawHash = hashes.get(sourceFile);
if (rawHash == null || digest == null) {
return null;
}
byte[] data = digest.digest(UTF8.getBytes(rawHash.toString()));
String tmp = new BigInteger(1, data).toString(16);
if (tmp.length() < 32) {
tmp = "000000000000000000000000000000000".substring(0, 32 - tmp.length()) + tmp;
}
return tmp;
}
代码示例来源:origin: redisson/redisson
private static String calcClassSign(String name) {
try {
Class<?> clazz = Class.forName(name);
ByteArrayOutputStream result = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(result);
outputStream.writeObject(clazz);
outputStream.close();
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(result.toByteArray());
return new BigInteger(1, crypt.digest()).toString(16);
} catch (Exception e) {
throw new IllegalStateException("Can't calculate sign of " + name, e);
}
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void encodeTest1() {
StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = sb.submitNewContract(
"contract A {" +
" int public a;" +
" function f(int a_) {a = a_;}" +
"}");
a.callFunction("f", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
BigInteger r = (BigInteger) a.callConstFunction("a")[0];
System.out.println(r.toString(16));
Assert.assertEquals(new BigInteger(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), r);
}
代码示例来源:origin: jfoenixadmin/JFoenix
public String nextSessionId() {
return new BigInteger(50, random).toString(16);
}
}
代码示例来源:origin: redisson/redisson
private static String calcClassSign(String name) {
try {
Class<?> clazz = Class.forName(name);
ByteArrayOutputStream result = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(result);
outputStream.writeObject(clazz);
outputStream.close();
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(result.toByteArray());
return new BigInteger(1, crypt.digest()).toString(16);
} catch (Exception e) {
throw new IllegalStateException("Can't calculate sign of " + name, e);
}
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void encodeTest2() {
StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = sb.submitNewContract(
"contract A {" +
" uint public a;" +
" function f(uint a_) {a = a_;}" +
"}");
a.callFunction("f", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
BigInteger r = (BigInteger) a.callConstFunction("a")[0];
System.out.println(r.toString(16));
Assert.assertEquals(new BigInteger(1, Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), r);
}
内容来源于网络,如有侵权,请联系作者删除!