Java Code Examples for org.bouncycastle.asn1.ASN1BitString

The following examples show how to use org.bouncycastle.asn1.ASN1BitString. 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: hedera-sdk-java   Source File:    License: Apache License 2.0 6 votes vote down vote up
private static Ed25519PrivateKey fromPrivateKeyInfo(PrivateKeyInfo privateKeyInfo) {
    Ed25519PrivateKeyParameters privKeyParams;
    Ed25519PublicKeyParameters pubKeyParams = null;

    try {
        ASN1Encodable privateKey = privateKeyInfo.parsePrivateKey();
        privKeyParams = new Ed25519PrivateKeyParameters(((ASN1OctetString) privateKey).getOctets(), 0);

        ASN1BitString pubKeyData = privateKeyInfo.getPublicKeyData();

        if (pubKeyData != null) {
            pubKeyParams = new Ed25519PublicKeyParameters(pubKeyData.getOctets(), 0);

    } catch (IOException e) {
        throw new BadKeyException(e);

    if (pubKeyParams != null) {
        return new Ed25519PrivateKey(privKeyParams, pubKeyParams);
    } else {
        return new Ed25519PrivateKey(privKeyParams);
Example 2
Source Project: ofdrw   Source File:    License: Apache License 2.0 5 votes vote down vote up
    public void verify() throws IOException, NoSuchAlgorithmException, CertificateException, InvalidKeyException, SignatureException {

        Path path = Paths.get("src/test/resources", "SignedValue.dat");
        Path srcPath = Paths.get("src/test/resources", "Signature.xml");

//        Path path = Paths.get("target", "UserV4.esl");
        SES_Signature sesSignature = SES_Signature.getInstance(Files.readAllBytes(path));

        MessageDigest md = new SM3.Digest();
        byte[] digest = md.digest(Files.readAllBytes(srcPath));
        final ASN1BitString dataHash = sesSignature.getToSign().getDataHash();
        System.out.println(Arrays.equals(digest, dataHash.getOctets()));

        ASN1OctetString cert = sesSignature.getCert();
        CertificateFactory factory = new CertificateFactory();
        X509Certificate certificate = (X509Certificate) factory.engineGenerateCertificate(cert.getOctetStream());

        TBS_Sign toSign = sesSignature.getToSign();

        Signature sg = Signature.getInstance(
                , new BouncyCastleProvider());
        byte[] sigVal = sesSignature.getSignature().getBytes();

Example 3
Source Project: dss   Source File:    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
private ASN1BitString rebuildASN1BitString(byte[] array) throws IOException {
	return (ASN1BitString) rebuildASN1Primitive(BERTags.BIT_STRING, array);