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


Java Crypto.verify方法代码示例

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


在下文中一共展示了Crypto.verify方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: parseToken

import nxt.crypto.Crypto; //导入方法依赖的package包/类
public static Token parseToken(String tokenString, String website) {

        byte[] websiteBytes = Convert.toBytes(website);
        byte[] tokenBytes = new byte[100];
        int i = 0, j = 0;

        for (; i < tokenString.length(); i += 8, j += 5) {

            long number = Long.parseLong(tokenString.substring(i, i + 8), 32);
            tokenBytes[j] = (byte)number;
            tokenBytes[j + 1] = (byte)(number >> 8);
            tokenBytes[j + 2] = (byte)(number >> 16);
            tokenBytes[j + 3] = (byte)(number >> 24);
            tokenBytes[j + 4] = (byte)(number >> 32);

        }

        if (i != 160) {
            throw new IllegalArgumentException("Invalid token string: " + tokenString);
        }
        byte[] publicKey = new byte[32];
        System.arraycopy(tokenBytes, 0, publicKey, 0, 32);
        int timestamp = (tokenBytes[32] & 0xFF) | ((tokenBytes[33] & 0xFF) << 8) | ((tokenBytes[34] & 0xFF) << 16) | ((tokenBytes[35] & 0xFF) << 24);
        byte[] signature = new byte[64];
        System.arraycopy(tokenBytes, 36, signature, 0, 64);

        byte[] data = new byte[websiteBytes.length + 36];
        System.arraycopy(websiteBytes, 0, data, 0, websiteBytes.length);
        System.arraycopy(tokenBytes, 0, data, websiteBytes.length, 36);
        boolean isValid = Crypto.verify(signature, data, publicKey, true);

        return new Token(publicKey, timestamp, isValid);

    }
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:35,代码来源:Token.java

示例3: verifySignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
public boolean verifySignature() {
    Account account = Account.getAccount(getSenderId());
    if (account == null) {
        return false;
    }
    if (signature == null) {
        return false;
    }
    byte[] data = zeroSignature(getBytes());
    return Crypto.verify(signature, data, senderPublicKey, useNQT()) && account.setOrVerify(senderPublicKey, this.getHeight());
}
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:12,代码来源:TransactionImpl.java

示例4: verifyBlockSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
boolean verifyBlockSignature() {

        Account account = Account.getAccount(getGeneratorId());
        if (account == null) {
            return false;
        }

        byte[] data = getBytes();
        byte[] data2 = new byte[data.length - 64];
        System.arraycopy(data, 0, data2, 0, data2.length);

        return Crypto.verify(blockSignature, data2, generatorPublicKey, version >= 3) && account.setOrVerify(generatorPublicKey, this.height);

    }
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:15,代码来源:BlockNXTImpl.java

示例5: checkSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
private boolean checkSignature() {
    if (! hasValidSignature) {
        byte[] data = Arrays.copyOf(bytes(), bytes.length - 64);
        hasValidSignature = blockSignature != null && Crypto.verify(blockSignature, data, getGeneratorPublicKey(), version >= 3);
    }
    return hasValidSignature;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:8,代码来源:BlockImpl.java

示例6: 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);
        try {
            return new Hallmark(hallmarkString, publicKey, signature, host, weight, date, isValid);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e.toString(), e);
        }

    }
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:35,代码来源:Hallmark.java

示例7: parseToken

import nxt.crypto.Crypto; //导入方法依赖的package包/类
public static Token parseToken(String tokenString, byte[] messageBytes) {
    byte[] tokenBytes = new byte[100];
    int i = 0, j = 0;

    for (; i < tokenString.length(); i += 8, j += 5) {

        long number = Long.parseLong(tokenString.substring(i, i + 8), 32);
        tokenBytes[j] = (byte)number;
        tokenBytes[j + 1] = (byte)(number >> 8);
        tokenBytes[j + 2] = (byte)(number >> 16);
        tokenBytes[j + 3] = (byte)(number >> 24);
        tokenBytes[j + 4] = (byte)(number >> 32);

    }

    if (i != 160) {
        throw new IllegalArgumentException("Invalid token string: " + tokenString);
    }
    byte[] publicKey = new byte[32];
    System.arraycopy(tokenBytes, 0, publicKey, 0, 32);
    int timestamp = (tokenBytes[32] & 0xFF) | ((tokenBytes[33] & 0xFF) << 8) | ((tokenBytes[34] & 0xFF) << 16) | ((tokenBytes[35] & 0xFF) << 24);
    byte[] signature = new byte[64];
    System.arraycopy(tokenBytes, 36, signature, 0, 64);

    byte[] data = new byte[messageBytes.length + 36];
    System.arraycopy(messageBytes, 0, data, 0, messageBytes.length);
    System.arraycopy(tokenBytes, 0, data, messageBytes.length, 36);
    byte[] announcedPublicKey = Account.getPublicKey(Account.getId(publicKey));
    boolean isValid = Crypto.verify(signature, data, publicKey, true)
            && (announcedPublicKey == null || Arrays.equals(publicKey, announcedPublicKey));

    return new Token(publicKey, timestamp, isValid);

}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:35,代码来源:Token.java

示例8: verifyBlockSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
boolean verifyBlockSignature() throws BlockchainProcessor.BlockOutOfOrderException {

    	try {
    		
    		BlockImpl previousBlock = (BlockImpl)Nxt.getBlockchain().getBlock(this.previousBlockId);
    		if (previousBlock == null) {
                throw new BlockchainProcessor.BlockOutOfOrderException("Can't verify signature because previous block is missing");
            }
    		
    		byte[] data = getBytes();
            byte[] data2 = new byte[data.length - 64];
            System.arraycopy(data, 0, data2, 0, data2.length);
            
            byte[] publicKey;
            Account genAccount = Account.getAccount(generatorPublicKey);
            Account.RewardRecipientAssignment rewardAssignment;
            rewardAssignment = genAccount == null ? null : genAccount.getRewardRecipientAssignment();
            if(genAccount == null ||
               rewardAssignment == null ||
               previousBlock.getHeight() + 1 < Constants.BURST_REWARD_RECIPIENT_ASSIGNMENT_START_BLOCK) {
            	publicKey = generatorPublicKey;
            }
            else {
            	if(previousBlock.getHeight() + 1 >= rewardAssignment.getFromHeight()) {
            		publicKey = Account.getAccount(rewardAssignment.getRecipientId()).getPublicKey();
            	}
            	else {
            		publicKey = Account.getAccount(rewardAssignment.getPrevRecipientId()).getPublicKey();
            	}
            }

            return Crypto.verify(blockSignature, data2, publicKey, version >= 3);
    		
    	} catch (RuntimeException e) {

    		Logger.logMessage("Error verifying block signature", e);
    		return false;

    	}

    }
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:42,代码来源:BlockImpl.java

示例9: verifySignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
public boolean verifySignature() {
    byte[] data = zeroSignature(getBytes());
    return Crypto.verify(signature, data, senderPublicKey, useNQT());
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:5,代码来源:TransactionImpl.java

示例10: verifyGenerationSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
boolean verifyGenerationSignature() {

        try {

            BlockNXTImpl previousBlock = (BlockNXTImpl) BlockchainImpl.getInstance().getBlock(getPreviousBlockId());
            if (previousBlock == null) {
                throw new RuntimeException("Can't verify signature because previous block is missing");
            }

            if (version == 1 && !Crypto.verify(generationSignature, previousBlock.generationSignature, generatorPublicKey, version >= 3)) {
                return false;
            }

            Account account = Account.getAccount(getGeneratorId());
            long effectiveBalance = account == null ? 0 : account.getEffectiveBalanceNXT();
            if (effectiveBalance <= 0) {
                return false;
            }

            MessageDigest digest = Crypto.sha256();
            byte[] generationSignatureHash;
            if (version == 1) {
                generationSignatureHash = digest.digest(generationSignature);
            } else {
                digest.update(previousBlock.generationSignature);
                generationSignatureHash = digest.digest(generatorPublicKey);
                if (!Arrays.equals(generationSignature, generationSignatureHash)) {
                    return false;
                }
            }

            BigInteger hit = new BigInteger(1, new byte[]{generationSignatureHash[7], generationSignatureHash[6], generationSignatureHash[5], generationSignatureHash[4], generationSignatureHash[3], generationSignatureHash[2], generationSignatureHash[1], generationSignatureHash[0]});

            return ProofOfNXT.verifyHit(hit, BigInteger.valueOf(effectiveBalance), previousBlock, timestamp);

        } catch (RuntimeException e) {

            Logger.logMessage("Error verifying block generation signature", e);
            return false;

        }

    }
 
开发者ID:giannisKonst,项目名称:blockchain,代码行数:44,代码来源:BlockNXTImpl.java

示例11: verifyGenerationSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
boolean verifyGenerationSignature() throws BlockchainProcessor.BlockOutOfOrderException {

        try {

            BlockImpl previousBlock = BlockchainImpl.getInstance().getBlock(getPreviousBlockId());
            if (previousBlock == null) {
                throw new BlockchainProcessor.BlockOutOfOrderException("Can't verify signature because previous block is missing", this);
            }

            if (version == 1 && !Crypto.verify(generationSignature, previousBlock.generationSignature, getGeneratorPublicKey(), version >= 3)) {
                return false;
            }

            Account account = Account.getAccount(getGeneratorId());
            long effectiveBalance = account == null ? 0 : account.getEffectiveBalanceNXT();
            if (effectiveBalance <= 0) {
                return false;
            }

            MessageDigest digest = Crypto.sha256();
            byte[] generationSignatureHash;
            if (version == 1) {
                generationSignatureHash = digest.digest(generationSignature);
            } else {
                digest.update(previousBlock.generationSignature);
                generationSignatureHash = digest.digest(getGeneratorPublicKey());
                if (!Arrays.equals(generationSignature, generationSignatureHash)) {
                    return false;
                }
            }

            BigInteger hit = new BigInteger(1, new byte[]{generationSignatureHash[7], generationSignatureHash[6], generationSignatureHash[5], generationSignatureHash[4], generationSignatureHash[3], generationSignatureHash[2], generationSignatureHash[1], generationSignatureHash[0]});
            // ignore bad block 6134843444354912879
            return Generator.verifyHit(hit, BigInteger.valueOf(effectiveBalance), previousBlock, timestamp) || (this.getId()==6134843444354912879L);                    

        } catch (RuntimeException e) {

            Logger.logMessage("Error verifying block generation signature", e);
            return false;

        }

    }
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:44,代码来源:BlockImpl.java

示例12: checkSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
private boolean checkSignature() {
    if (!hasValidSignature) {
        hasValidSignature = signature != null && Crypto.verify(signature, zeroSignature(getBytes()), getSenderPublicKey(), useNQT());
    }
    return hasValidSignature;
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:7,代码来源:TransactionImpl.java

示例13: verifyGenerationSignature

import nxt.crypto.Crypto; //导入方法依赖的package包/类
boolean verifyGenerationSignature() throws BlockchainProcessor.BlockOutOfOrderException {

        try {

            BlockImpl previousBlock = BlockchainImpl.getInstance().getBlock(getPreviousBlockId());
            if (previousBlock == null) {
                throw new BlockchainProcessor.BlockOutOfOrderException("Can't verify signature because previous block is missing");
            }

            if (version == 1 && !Crypto.verify(generationSignature, previousBlock.generationSignature, generatorPublicKey, version >= 3)) {
                return false;
            }

            Account account = Account.getAccount(getGeneratorId());
            long effectiveBalance = account == null ? 0 : account.getEffectiveBalanceNXT();
            if (effectiveBalance <= 0) {
                return false;
            }

            MessageDigest digest = Crypto.sha256();
            byte[] generationSignatureHash;
            if (version == 1) {
                generationSignatureHash = digest.digest(generationSignature);
            } else {
                digest.update(previousBlock.generationSignature);
                generationSignatureHash = digest.digest(generatorPublicKey);
                if (!Arrays.equals(generationSignature, generationSignatureHash)) {
                    return false;
                }
            }

            BigInteger hit = new BigInteger(1, new byte[]{generationSignatureHash[7], generationSignatureHash[6], generationSignatureHash[5], generationSignatureHash[4], generationSignatureHash[3], generationSignatureHash[2], generationSignatureHash[1], generationSignatureHash[0]});

            return Generator.verifyHit(hit, BigInteger.valueOf(effectiveBalance), previousBlock, timestamp)
                    || (this.height < Constants.TRANSPARENT_FORGING_BLOCK_5 && Arrays.binarySearch(badBlocks, this.getId()) >= 0);

        } catch (RuntimeException e) {

            Logger.logMessage("Error verifying block generation signature", e);
            return false;

        }

    }
 
开发者ID:Ziftr,项目名称:nxt,代码行数:45,代码来源:BlockImpl.java


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