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


Java Numeric.toBytesPadded方法代码示例

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


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

示例1: decodeKeyPair

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static KeyPair decodeKeyPair(ECKeyPair ecKeyPair) {
    byte[] bytes = Numeric.toBytesPadded(ecKeyPair.getPublicKey(), 64);
    BigInteger x = Numeric.toBigInt(Arrays.copyOfRange(bytes, 0, 32));
    BigInteger y = Numeric.toBigInt(Arrays.copyOfRange(bytes, 32, 64));
    ECPoint q = curve.createPoint(x, y);
    BCECPublicKey publicKey = new BCECPublicKey(ALGORITHM, new ECPublicKeyParameters(q, dp), BouncyCastleProvider.CONFIGURATION);
    BCECPrivateKey privateKey = new BCECPrivateKey(ALGORITHM, new ECPrivateKeyParameters(ecKeyPair.getPrivateKey(), dp), publicKey, p, BouncyCastleProvider.CONFIGURATION);
    return new KeyPair(publicKey, privateKey);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:10,代码来源:CryptoUtil.java

示例2: serialize

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static byte[] serialize(ECKeyPair ecKeyPair) {
    byte[] privateKey = Numeric.toBytesPadded(ecKeyPair.getPrivateKey(), PRIVATE_KEY_SIZE);
    byte[] publicKey = Numeric.toBytesPadded(ecKeyPair.getPublicKey(), PUBLIC_KEY_SIZE);

    byte[] result = Arrays.copyOf(privateKey, PRIVATE_KEY_SIZE + PUBLIC_KEY_SIZE);
    System.arraycopy(publicKey, 0, result, PRIVATE_KEY_SIZE, PUBLIC_KEY_SIZE);
    return result;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:9,代码来源:Keys.java

示例3: signMessage

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static SignatureData signMessage(byte[] message, ECKeyPair keyPair) {
    BigInteger publicKey = keyPair.getPublicKey();

    byte[] messageHash = Hash.sha3(message);

    ECDSASignature sig = keyPair.sign(messageHash);
    // Now we have to work backwards to figure out the recId needed to recover the signature.
    int recId = -1;
    for (int i = 0; i < 4; i++) {
        BigInteger k = recoverFromSignature(i, sig, messageHash);
        if (k != null && k.equals(publicKey)) {
            recId = i;
            break;
        }
    }
    if (recId == -1) {
        throw new RuntimeException(
                "Could not construct a recoverable key. This should never happen.");
    }

    int headerByte = recId + 27;

    // 1 header + 32 bytes for R + 32 bytes for S
    byte v = (byte) headerByte;
    byte[] r = Numeric.toBytesPadded(sig.r, 32);
    byte[] s = Numeric.toBytesPadded(sig.s, 32);

    return new SignatureData(v, r, s);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:30,代码来源:Sign.java

示例4: serialize

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Override
public ByteBuffer serialize(Uint256 value, ProtocolVersion protocolVersion) throws InvalidTypeException {
    if (value == null) return null;
    byte[] bytes = Numeric.toBytesPadded(value.getValue(), BYTES);
    return ByteBuffer.wrap(bytes);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:7,代码来源:UInt256Codec.java

示例5: serialize

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
@Override
public ByteBuffer serialize(Address value, ProtocolVersion protocolVersion) throws InvalidTypeException {
    if (value == null) return null;
    byte[] bytes = Numeric.toBytesPadded(value.toUint160().getValue(), BYTES);
    return ByteBuffer.wrap(bytes);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:7,代码来源:AddressCodec.java

示例6: create

import org.web3j.utils.Numeric; //导入方法依赖的package包/类
public static WalletFile create(String password, ECKeyPair ecKeyPair, int n, int p)
        throws CipherException {

    byte[] salt = generateRandomBytes(32);

    byte[] derivedKey = generateDerivedScryptKey(
            password.getBytes(UTF_8), salt, n, R, p, DKLEN);

    byte[] encryptKey = Arrays.copyOfRange(derivedKey, 0, 16);
    byte[] iv = generateRandomBytes(16);

    byte[] privateKeyBytes =
            Numeric.toBytesPadded(ecKeyPair.getPrivateKey(), Keys.PRIVATE_KEY_SIZE);

    byte[] cipherText = performCipherOperation(
                Cipher.ENCRYPT_MODE, iv, encryptKey, privateKeyBytes);

    byte[] mac = generateMac(derivedKey, cipherText);

    return createWalletFile(ecKeyPair, cipherText, iv, salt, mac, n, p);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:22,代码来源:Wallet.java


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