当前位置: 首页>>代码示例>>Java>>正文


Java Crypto类代码示例

本文整理汇总了Java中nxt.crypto.Crypto的典型用法代码示例。如果您正苦于以下问题:Java Crypto类的具体用法?Java Crypto怎么用?Java Crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Crypto类属于nxt.crypto包,在下文中一共展示了Crypto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的nxt.crypto.Crypto类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。