C
C
created4dev2014-12-04 11:51:20
Java
created4dev, 2014-12-04 11:51:20

How to check EDS in xml on java?

From xml I take lines: data2=, sign2=, cert2=.
I try to check the EDS, but it always gives out "false". What am I doing wrong?

import java.io.ByteArrayInputStream;
import java.security.PublicKey;
import java.security.Security;
import java.security.Signature;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
import kz.iola.jce.provider.IolaProvider;
import kz.iola.util.encoders.Base64;

public class Test2 {
  
  public static void main(String[] args) {
    try {
      Security.addProvider(new IolaProvider());
      String cert2="MIIGyzCCBnSgAwIBAgIgd32h0nI8xKcclvcVEK2L7nztSMJllua8eafUM1d6BfMwDgYKKwYBBAG1EQECAgUAMIIBFDEfMB0GA1UEAwwW0J3Qo9CmINCg0JogKNCT0J7QodCiKTFDMEEGA1UECww60JjQvdGE0YDQsNGB0YLRgNGD0LrRgtGD0YDQsCDQvtGC0LrRgNGL0YLRi9GFINC60LvRjtGH0LXQuTFxMG8GA1UECgxo0J3QsNGG0LjQvtC90LDQu9GM0L3Ri9C5INGD0LTQvtGB0YLQvtCy0LXRgNGP0Y7RidC40Lkg0YbQtdC90YLRgCDQoNC10YHQv9GD0LHQu9C40LrQuCDQmtCw0LfQsNGF0YHRgtCw0L0xFTATBgNVBAcMDNCQ0YHRgtCw0L3QsDEVMBMGA1UECAwM0JDRgdGC0LDQvdCwMQswCQYDVQQGEwJLWjAeFw0xNDAxMTAwNTE5MTdaFw0xNTAxMTAwNTE5MTdaMIIB9TEYMBYGA1UEBRMPSUlONzIwNzI1NDAyMDg0MRgwFgYDVQQLDA9CSU4wODA1NDAwMTQ4NTQxgf0wgfoGA1UECgyB8tCT0J7QodCj0JTQkNCg0KHQotCS0JXQndCd0J7QlSDQo9Cn0KDQldCW0JTQldCd0JjQlSAi0JrQntCc0JjQotCV0KIg0KDQldCT0JjQodCi0KDQkNCm0JjQntCd0J3QntCZINCh0JvQo9CW0JHQqyDQmCDQntCa0JDQl9CQ0J3QmNCvINCf0KDQkNCS0J7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oft4Pfl7ejlIC0g8fTl8OAg3evl6vLw7u3t7uPuIM/w4OLo8uXr/PHy4uAwewYHKoMOAwMBATBwMDAGCCsGAQUFBwIBFiRodHRwOi8vcGtpLmdvdi5rei9pbmZvL2NhX3BvbGljeS5wZGYwPAYIKwYBBQUHAgIwMBou0OXj6+Ds5e3yIM3g9uju7eDr/O3u4+4g0+Tu8fLu4uXw//755ePuINbl7fLw4DATBgNVHSUEDDAKBggrBgEFBQcDBDBYBgNVHR8EUTBPMCWgI6Ahhh9odHRwOi8vY3JsLnBraS5rei9jcmwvR29zdDAuY3JsMCagJKAihiBodHRwOi8vY3JsMS5wa2kua3ovY3JsL0dvc3QwLmNybDAOBgorBgEEAbURAQICBQADQQBTEzXTkGihlUbbfdZVostXzC3dcrZlObF7yKYVCiWTTEuLdmOTFZcAHL1POPRbJw9spEzfJWi2pe9BEAwZxt1W";
      String data2="8nbPMk3F5v++1YnYKGs/Mh2mU7yn3Ymq2PkYv5DVnAQ=";
      String sign2="AQL0C3JNQJGQKqkgciGvnpU5zQcgz34LdWkGqFvABMpq0aUi9BveyspglZEgj7IqVXWcc1+FMQIKp/XuLUgciA==";

      Certificate certificate2 = CertificateFactory.getInstance("X509").generateCertificate(new ByteArrayInputStream(Base64.decode(cert2)));
      PublicKey publicKey=certificate2.getPublicKey();
      Signature signature2 = Signature.getInstance(publicKey.getAlgorithm(), IolaProvider.PROVIDER_NAME);
      signature2.initVerify(publicKey);
      signature2.update(Base64.decode(data2));
      System.out.print(signature2.verify(Base64.decode(sign2)));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Power, 2014-12-05
@Power

Signature signature2 = Signature.getInstance(publicKey.getAlgorithm(), IolaProvider.PROVIDER_NAME);

Are you sure that the public key algorithm matches the signature algorithm?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question