Java Code Examples for org.bouncycastle.pqc.math.linearalgebra.ByteUtils#toHexString()

The following examples show how to use org.bouncycastle.pqc.math.linearalgebra.ByteUtils#toHexString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gmhelper   File: SM2PrivateKeyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEncoded() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
    KeyPair keyPair = SM2Util.generateKeyPair();
    BCECPrivateKey privateKey = (BCECPrivateKey) keyPair.getPrivate();
    BCECPublicKey publicKey = (BCECPublicKey) keyPair.getPublic();
    SM2PublicKey sm2PublicKey = new SM2PublicKey(publicKey.getAlgorithm(), publicKey);
    SM2PrivateKey sm2PrivateKey1 = new SM2PrivateKey(privateKey, publicKey);
    SM2PrivateKey sm2PrivateKey2 = new SM2PrivateKey(privateKey, sm2PublicKey);
    String nativePriDER = ByteUtils.toHexString(privateKey.getEncoded());
    String sm2PriDER1 = ByteUtils.toHexString(sm2PrivateKey1.getEncoded());
    String sm2PriDER2 = ByteUtils.toHexString(sm2PrivateKey2.getEncoded());
    if (nativePriDER.equalsIgnoreCase(sm2PriDER1)) {
        Assert.fail();
    }
    if (!sm2PriDER1.equalsIgnoreCase(sm2PriDER2)) {
        Assert.fail();
    }
    System.out.println("Native EC Private Key DER:\n" + nativePriDER.toUpperCase());
    System.out.println("SM2 EC Private Key DER:\n" + sm2PriDER1.toUpperCase());
}
 
Example 2
/**
 * read pem and convert to address.
 * @param s pem file context
 * @return address
 * @throws Exception -
 */
public static String pemToAddr(String s) throws Exception {
    PemReader pemReader = new PemReader(new StringReader(s));
    PemObject pemObject = pemReader.readPemObject();
    X509CertificateHolder cert = new X509CertificateHolder(pemObject.getContent());
    SubjectPublicKeyInfo pkInfo = cert.getSubjectPublicKeyInfo();
    DERBitString pk = pkInfo.getPublicKeyData();
    byte[] pk64 = ByteUtils.subArray(pk.getBytes(),1);
    return ByteUtils.toHexString(HashUtil.sha3omit12(pk64));
}
 
Example 3
Source Project: Groza   File: EncryptionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getSha3Hash(String data) {
    String trimmedData = trimNewLines(data);
    byte[] dataBytes = trimmedData.getBytes();
    SHA3Digest md = new SHA3Digest(256);
    md.reset();
    md.update(dataBytes, 0, dataBytes.length);
    byte[] hashedBytes = new byte[256 / 8];
    md.doFinal(hashedBytes, 0);
    String sha3Hash = ByteUtils.toHexString(hashedBytes);
    return sha3Hash;
}
 
Example 4
Source Project: iotplatform   File: EncryptionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getSha3Hash(String data) {
    String trimmedData = trimNewLines(data);
    byte[] dataBytes = trimmedData.getBytes();
    SHA3Digest md = new SHA3Digest(256);
    md.reset();
    md.update(dataBytes, 0, dataBytes.length);
    byte[] hashedBytes = new byte[256 / 8];
    md.doFinal(hashedBytes, 0);
    String sha3Hash = ByteUtils.toHexString(hashedBytes);
    return sha3Hash;
}