本文整理汇总了Java中nxt.crypto.Crypto类的典型用法代码示例。如果您正苦于以下问题:Java Crypto类的具体用法?Java Crypto怎么用?Java Crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Crypto类属于nxt.crypto包,在下文中一共展示了Crypto类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: processRequest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
String unsignedBytesString = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes"));
String signatureHashString = Convert.emptyToNull(req.getParameter("signatureHash"));
if (unsignedBytesString == null) {
return MISSING_UNSIGNED_BYTES;
} else if (signatureHashString == null) {
return MISSING_SIGNATURE_HASH;
}
MessageDigest digest = Crypto.sha256();
digest.update(Convert.parseHexString(unsignedBytesString));
byte[] fullHash = digest.digest(Convert.parseHexString(signatureHashString));
JSONObject response = new JSONObject();
response.put("fullHash", Convert.toHexString(fullHash));
return response;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:22,代码来源:CalculateFullHash.java
示例2: processRequest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) {
long accountId;
String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase"));
String publicKeyString = Convert.emptyToNull(req.getParameter("publicKey"));
if (secretPhrase != null) {
byte[] publicKey = Crypto.getPublicKey(secretPhrase);
accountId = Account.getId(publicKey);
publicKeyString = Convert.toHexString(publicKey);
} else if (publicKeyString != null) {
accountId = Account.getId(Convert.parseHexString(publicKeyString));
} else {
return MISSING_SECRET_PHRASE_OR_PUBLIC_KEY;
}
JSONObject response = new JSONObject();
JSONData.putAccount(response, "account", accountId);
response.put("publicKey", publicKeyString);
return response;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:23,代码来源:GetAccountId.java
示例3: getSenderAccount
import nxt.crypto.Crypto; //导入依赖的package包/类
static Account getSenderAccount(HttpServletRequest req) throws ParameterException {
Account account;
String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase"));
String publicKeyString = Convert.emptyToNull(req.getParameter("publicKey"));
if (secretPhrase != null) {
account = Account.getAccount(Crypto.getPublicKey(secretPhrase));
} else if (publicKeyString != null) {
try {
account = Account.getAccount(Convert.parseHexString(publicKeyString));
} catch (RuntimeException e) {
throw new ParameterException(INCORRECT_PUBLIC_KEY);
}
} else {
throw new ParameterException(MISSING_SECRET_PHRASE_OR_PUBLIC_KEY);
}
if (account == null) {
throw new ParameterException(UNKNOWN_ACCOUNT);
}
return account;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:21,代码来源:ParameterParser.java
示例4: addNonce
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
public GeneratorState addNonce(String secretPhrase, Long nonce, byte[] publicKey) {
byte[] publicKeyHash = Crypto.sha256().digest(publicKey);
Long id = Convert.fullHashToId(publicKeyHash);
GeneratorStateImpl generator = new GeneratorStateImpl(secretPhrase, nonce, publicKey, id);
GeneratorStateImpl curGen = generators.get(id);
if(curGen == null || generator.getBlock() > curGen.getBlock() || generator.getDeadline().compareTo(curGen.getDeadline()) < 0) {
generators.put(id, generator);
listeners.notify(generator, Event.START_FORGING);
Logger.logDebugMessage("Account " + Convert.toUnsignedLong(id) + " started mining, deadline "
+ generator.getDeadline() + " seconds");
}
else {
Logger.logDebugMessage("Account " + Convert.toUnsignedLong(id) + " already has better nonce");
}
return generator;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:20,代码来源:GeneratorImpl.java
示例5: BlockNXTImpl
import nxt.crypto.Crypto; //导入依赖的package包/类
BlockNXTImpl(int timestamp, Block previousBlock1, byte[] publicKey, List<TransactionImpl> transactions) throws NxtException.ValidationException {
/* super(version, timestamp, previousBlockId, totalAmountNQT, totalFeeNQT, payloadLength, payloadHash,
previousBlockHash, List<TransactionImpl> transactions); */
super(timestamp, previousBlock1, transactions);
BlockNXTImpl previousBlock = (BlockNXTImpl) previousBlock1;
MessageDigest digest = Crypto.sha256();
digest.update(previousBlock.getGenerationSignature());
byte[] generationSignature = digest.digest(publicKey);
byte[] previousBlockHash = previousBlock.getHash();
this.version = 3;
this.generatorPublicKey = publicKey;
this.generationSignature = generationSignature;
this.blockSignature = blockSignature;
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:19,代码来源:BlockNXTImpl.java
示例6: manualForgingTest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Test
public void manualForgingTest() {
Properties properties = ManualForgingTest.newTestProperties();
properties.setProperty("nxt.enableFakeForging", "true");
properties.setProperty("nxt.timeMultiplier", "1");
AbstractForgingTest.init(properties);
Assert.assertTrue("nxt.fakeForgingAccount must be defined in nxt.properties", Nxt.getStringProperty("nxt.fakeForgingAccount") != null);
final byte[] testPublicKey = Crypto.getPublicKey(testForgingSecretPhrase);
Nxt.setTime(new Time.CounterTime(Nxt.getEpochTime()));
try {
for (int i = 0; i < 10; i++) {
blockchainProcessor.generateBlock(testForgingSecretPhrase, Nxt.getEpochTime());
Assert.assertArrayEquals(testPublicKey, blockchain.getLastBlock().getGeneratorPublicKey());
}
} catch (BlockchainProcessor.BlockNotAcceptedException e) {
throw new RuntimeException(e.toString(), e);
}
Assert.assertEquals(startHeight + 10, blockchain.getHeight());
AbstractForgingTest.shutdown();
}
开发者ID:Ziftr,项目名称:nxt,代码行数:21,代码来源:ManualForgingTest.java
示例7: currencyMint
import nxt.crypto.Crypto; //导入依赖的package包/类
private JSONObject currencyMint(String secretPhrase, long currencyId, long nonce, long units, long counter) {
JSONObject ecBlock = getECBlock();
Attachment attachment = new Attachment.MonetarySystemCurrencyMinting(nonce, currencyId, units, counter);
Transaction.Builder builder = Nxt.newTransactionBuilder(Crypto.getPublicKey(secretPhrase), 0, Constants.ONE_NXT,
(short) 120, attachment)
.timestamp(((Long) ecBlock.get("timestamp")).intValue())
.ecBlockHeight(((Long) ecBlock.get("ecBlockHeight")).intValue())
.ecBlockId(Convert.parseUnsignedLong((String) ecBlock.get("ecBlockId")));
try {
Transaction transaction = builder.build();
transaction.sign(secretPhrase);
Map<String, String> params = new HashMap<>();
params.put("requestType", "broadcastTransaction");
params.put("transactionBytes", Convert.toHexString(transaction.getBytes()));
return getJsonResponse(params);
} catch (NxtException.NotValidException e) {
Logger.logInfoMessage("local signing failed", e);
JSONObject response = new JSONObject();
response.put("error", e.toString());
return response;
}
}
开发者ID:giannisKonst,项目名称:blockchain,代码行数:23,代码来源:MintWorker.java
示例8: processRequest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
String unsignedBytesString = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes"));
String signatureHashString = Convert.emptyToNull(req.getParameter("signatureHash"));
String unsignedTransactionJSONString = Convert.emptyToNull(req.getParameter("unsignedTransactionJSON"));
if (signatureHashString == null) {
return MISSING_SIGNATURE_HASH;
}
JSONObject response = new JSONObject();
try {
Transaction transaction = ParameterParser.parseTransaction(unsignedTransactionJSONString, unsignedBytesString, null).build();
MessageDigest digest = Crypto.sha256();
digest.update(transaction.getUnsignedBytes());
byte[] fullHash = digest.digest(Convert.parseHexString(signatureHashString));
response.put("fullHash", Convert.toHexString(fullHash));
} catch (NxtException.NotValidException e) {
JSONData.putException(response, e, "Incorrect unsigned transaction json or bytes");
}
return response;
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:23,代码来源:CalculateFullHash.java
示例9: processRequest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase"));
int elapsedTime = Nxt.getEpochTime() - Nxt.getBlockchain().getLastBlock().getTimestamp();
if (secretPhrase != null) {
Account account = Account.getAccount(Crypto.getPublicKey(secretPhrase));
if (account == null) {
return UNKNOWN_ACCOUNT;
}
Generator generator = Generator.getGenerator(secretPhrase);
if (generator == null) {
return NOT_FORGING;
}
return JSONData.generator(generator, elapsedTime);
} else {
API.verifyPassword(req);
JSONObject response = new JSONObject();
JSONArray generators = new JSONArray();
Generator.getSortedForgers().forEach(generator -> generators.add(JSONData.generator(generator, elapsedTime)));
response.put("generators", generators);
return response;
}
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:25,代码来源:GetForging.java
示例10: currencyMint
import nxt.crypto.Crypto; //导入依赖的package包/类
private JSONObject currencyMint(String secretPhrase, long currencyId, long nonce, long units, long counter) {
JSONObject ecBlock = getECBlock();
Attachment attachment = new Attachment.MonetarySystemCurrencyMinting(nonce, currencyId, units, counter);
Transaction.Builder builder = Nxt.newTransactionBuilder(Crypto.getPublicKey(secretPhrase), 0, Constants.ONE_NXT,
(short) 120, attachment)
.timestamp(((Long) ecBlock.get("timestamp")).intValue())
.ecBlockHeight(((Long) ecBlock.get("ecBlockHeight")).intValue())
.ecBlockId(Convert.parseUnsignedLong((String) ecBlock.get("ecBlockId")));
try {
Transaction transaction = builder.build(secretPhrase);
Map<String, String> params = new HashMap<>();
params.put("requestType", "broadcastTransaction");
params.put("transactionBytes", Convert.toHexString(transaction.getBytes()));
return getJsonResponse(params);
} catch (NxtException.NotValidException e) {
Logger.logInfoMessage("local signing failed", e);
JSONObject response = new JSONObject();
response.put("error", e.toString());
return response;
}
}
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:22,代码来源:MintWorker.java
示例11: init
import nxt.crypto.Crypto; //导入依赖的package包/类
@Before
public void init() {
id1 = Account.getAccount(Crypto.getPublicKey(secretPhrase1)).getId();
id2 = Account.getAccount(Crypto.getPublicKey(secretPhrase2)).getId();
id3 = Account.getAccount(Crypto.getPublicKey(secretPhrase3)).getId();
id4 = Account.getAccount(Crypto.getPublicKey(secretPhrase4)).getId();
Properties properties = ManualForgingTest.newTestProperties();
properties.setProperty("nxt.isTestnet", "true");
properties.setProperty("nxt.isOffline", "true");
properties.setProperty("nxt.enableFakeForging", "true");
properties.setProperty("nxt.timeMultiplier", "1");
AbstractForgingTest.init(properties);
Nxt.setTime(new Time.CounterTime(Nxt.getEpochTime()));
baseHeight = blockchain.getHeight();
Logger.logMessage("baseHeight: " + baseHeight);
}
开发者ID:Ziftr,项目名称:nxt,代码行数:18,代码来源:BlockchainTest.java
示例12: addGenesisBlock
import nxt.crypto.Crypto; //导入依赖的package包/类
private void addGenesisBlock() {
if (BlockDb.hasBlock(Genesis.GENESIS_BLOCK_ID)) {
Logger.logMessage("Genesis block already in database");
BlockImpl lastBlock = BlockDb.findLastBlock();
blockchain.setLastBlock(lastBlock);
Logger.logMessage("Last block height: " + lastBlock.getHeight());
return;
}
Logger.logMessage("Genesis block not in database, starting from scratch");
try {
List<TransactionImpl> transactions = new ArrayList<>();
MessageDigest digest = Crypto.sha256();
for (Transaction transaction : transactions) {
digest.update(transaction.getBytes());
}
ByteBuffer bf = ByteBuffer.allocate( 0 );
bf.order( ByteOrder.LITTLE_ENDIAN );
byte[] byteATs = bf.array();
BlockImpl genesisBlock = new BlockImpl(-1, 0, 0, 0, 0, transactions.size() * 128, digest.digest(),
Genesis.CREATOR_PUBLIC_KEY, new byte[32], Genesis.GENESIS_BLOCK_SIGNATURE, null, transactions, 0, byteATs);
genesisBlock.setPrevious(null);
addBlock(genesisBlock);
} catch (NxtException.ValidationException e) {
Logger.logMessage(e.getMessage());
throw new RuntimeException(e.toString(), e);
}
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:28,代码来源:BlockchainProcessorImpl.java
示例13: getId
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
public long getId() {
if (id == 0) {
if (blockSignature == null) {
throw new IllegalStateException("Block is not signed yet");
}
byte[] hash = Crypto.sha256().digest(getBytes());
BigInteger bigInteger = new BigInteger(1, new byte[] {hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]});
id = bigInteger.longValue();
stringId = bigInteger.toString();
}
return id;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:14,代码来源:BlockImpl.java
示例14: sign
import nxt.crypto.Crypto; //导入依赖的package包/类
void sign(String secretPhrase) {
if (blockSignature != null) {
throw new IllegalStateException("Block already signed");
}
blockSignature = new byte[64];
byte[] data = getBytes();
byte[] data2 = new byte[data.length - 64];
System.arraycopy(data, 0, data2, 0, data2.length);
blockSignature = Crypto.sign(data2, secretPhrase);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:11,代码来源:BlockImpl.java
示例15: sign
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
public void sign(String secretPhrase) {
if (signature != null) {
throw new IllegalStateException("Transaction already signed");
}
signature = Crypto.sign(getBytes(), secretPhrase);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:8,代码来源:TransactionImpl.java
示例16: processRequest
import nxt.crypto.Crypto; //导入依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {
String transactionBytes = Convert.emptyToNull(req.getParameter("unsignedTransactionBytes"));
String transactionJSON = Convert.emptyToNull(req.getParameter("unsignedTransactionJSON"));
Transaction transaction = ParameterParser.parseTransaction(transactionBytes, transactionJSON);
String secretPhrase = Convert.emptyToNull(req.getParameter("secretPhrase"));
if (secretPhrase == null) {
return MISSING_SECRET_PHRASE;
}
JSONObject response = new JSONObject();
try {
transaction.validate();
if (transaction.getSignature() != null) {
response.put("errorCode", 4);
response.put("errorDescription", "Incorrect unsigned transaction - already signed");
return response;
}
if (! Arrays.equals(Crypto.getPublicKey(secretPhrase), transaction.getSenderPublicKey())) {
response.put("errorCode", 4);
response.put("errorDescription", "Secret phrase doesn't match transaction sender public key");
return response;
}
transaction.sign(secretPhrase);
response.put("transaction", transaction.getStringId());
response.put("fullHash", transaction.getFullHash());
response.put("transactionBytes", Convert.toHexString(transaction.getBytes()));
response.put("signatureHash", Convert.toHexString(Crypto.sha256().digest(transaction.getSignature())));
response.put("verify", transaction.verifySignature() && transaction.verifyPublicKey());
} catch (NxtException.ValidationException|RuntimeException e) {
Logger.logDebugMessage(e.getMessage(), e);
response.put("errorCode", 4);
response.put("errorDescription", "Incorrect unsigned transaction: " + e.toString());
response.put("error", e.getMessage());
return response;
}
return response;
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:41,代码来源:SignTransaction.java
示例17: Account
import nxt.crypto.Crypto; //导入依赖的package包/类
private Account(long id) {
if (id != Crypto.rsDecode(Crypto.rsEncode(id))) {
Logger.logMessage("CRITICAL ERROR: Reed-Solomon encoding fails for " + id);
}
this.id = id;
this.dbKey = accountDbKeyFactory.newKey(this.id);
this.creationHeight = Nxt.getBlockchain().getHeight();
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:9,代码来源:Account.java
示例18: generateHallmark
import nxt.crypto.Crypto; //导入依赖的package包/类
public static String generateHallmark(String secretPhrase, String host, int weight, int date) {
if (host.length() == 0 || host.length() > 100) {
throw new IllegalArgumentException("Hostname length should be between 1 and 100");
}
if (weight <= 0 || weight > Constants.MAX_BALANCE_NXT) {
throw new IllegalArgumentException("Weight should be between 1 and " + Constants.MAX_BALANCE_NXT);
}
byte[] publicKey = Crypto.getPublicKey(secretPhrase);
byte[] hostBytes = Convert.toBytes(host);
ByteBuffer buffer = ByteBuffer.allocate(32 + 2 + hostBytes.length + 4 + 4 + 1);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put(publicKey);
buffer.putShort((short)hostBytes.length);
buffer.put(hostBytes);
buffer.putInt(weight);
buffer.putInt(date);
byte[] data = buffer.array();
data[data.length - 1] = (byte) ThreadLocalRandom.current().nextInt();
byte[] signature = Crypto.sign(data, secretPhrase);
return Convert.toHexString(data) + Convert.toHexString(signature);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:28,代码来源:Hallmark.java
示例19: parseHallmark
import nxt.crypto.Crypto; //导入依赖的package包/类
public static Hallmark parseHallmark(String hallmarkString) {
byte[] hallmarkBytes = Convert.parseHexString(hallmarkString);
ByteBuffer buffer = ByteBuffer.wrap(hallmarkBytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
byte[] publicKey = new byte[32];
buffer.get(publicKey);
int hostLength = buffer.getShort();
if (hostLength > 300) {
throw new IllegalArgumentException("Invalid host length");
}
byte[] hostBytes = new byte[hostLength];
buffer.get(hostBytes);
String host = Convert.toString(hostBytes);
int weight = buffer.getInt();
int date = buffer.getInt();
buffer.get();
byte[] signature = new byte[64];
buffer.get(signature);
byte[] data = new byte[hallmarkBytes.length - 64];
System.arraycopy(hallmarkBytes, 0, data, 0, data.length);
boolean isValid = host.length() < 100 && weight > 0 && weight <= Constants.MAX_BALANCE_NXT
&& Crypto.verify(signature, data, publicKey, true);
return new Hallmark(hallmarkString, publicKey, signature, host, weight, date, isValid);
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:32,代码来源:Hallmark.java
示例20: parseAccountId
import nxt.crypto.Crypto; //导入依赖的package包/类
public static long parseAccountId(String account) {
if (account == null) {
return 0;
}
account = account.toUpperCase();
if (account.startsWith("BURST-")) {
return Crypto.rsDecode(account.substring(6));
} else {
return parseUnsignedLong(account);
}
}
开发者ID:muhatzg,项目名称:burstcoin,代码行数:12,代码来源:Convert.java
注:本文中的nxt.crypto.Crypto类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论