From 37ddd3d075d0664de44f05639712869596bfb9cd Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:30:19 +0100 Subject: ssb added to encoder and decoder --- .../java/org/uic/barcode/ssbFrame/SsbFrame.java | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/uic/barcode/ssbFrame/SsbFrame.java') diff --git a/src/main/java/org/uic/barcode/ssbFrame/SsbFrame.java b/src/main/java/org/uic/barcode/ssbFrame/SsbFrame.java index b496b17..81b5eb4 100644 --- a/src/main/java/org/uic/barcode/ssbFrame/SsbFrame.java +++ b/src/main/java/org/uic/barcode/ssbFrame/SsbFrame.java @@ -7,6 +7,7 @@ import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.Provider; import java.security.PublicKey; +import java.security.Security; import java.security.Signature; import java.security.SignatureException; import java.security.Provider.Service; @@ -198,16 +199,18 @@ public class SsbFrame { this.passData = passData; } - public void signLevel1(PrivateKey key, Provider prov, String algorithmOid) throws Exception { + public void signLevel1(PrivateKey key, Provider prov, String keyId, String algorithmOid) throws Exception { + this.header.setKeyId(Integer.parseInt(keyId)); + byte[] data = getDataForSignature(); if (prov == null) { //check for a provider supporting the key prov = SecurityUtils.findPrivateKeyProvider(key); } - + //find the algorithm name for the signature OID String algo = AlgorithmNameResolver.getSignatureAlgorithmName(algorithmOid, prov); Signature sig = null; @@ -261,10 +264,25 @@ public class SsbFrame { public boolean verifyByAlgorithmOid(PublicKey key, String signingAlg, Provider prov) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException, IllegalArgumentException, UnsupportedOperationException, IOException, EncodingFormatException { //find the algorithm name for the signature OID String algo = null; - Service service = prov.getService("Signature",signingAlg); - if (service != null) { - algo = service.getAlgorithm(); - } + + if (prov != null) { + Service service = prov.getService("Signature",signingAlg); + if (service != null) { + algo = service.getAlgorithm(); + } + } else { + Provider[] provs = Security.getProviders(); + for (Provider p : provs) { + if (algo == null) { + Service service = p.getService("Signature",signingAlg); + if (service != null) { + algo = service.getAlgorithm(); + } + } + } + + } + if (algo == null) { throw new NoSuchAlgorithmException("No service for algorithm found: " + signingAlg); } @@ -279,4 +297,6 @@ public class SsbFrame { return sig.verify(signature); } + + } -- cgit v1.2.3