From 6eebf3f29b9658a4e74ab1d1f90146c8e029c736 Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Mon, 28 Jun 2021 17:28:50 +0200 Subject: - option to use a dedicated security provider implementation --- src/main/java/org/uic/barcode/Encoder.java | 44 +++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/uic/barcode/Encoder.java') diff --git a/src/main/java/org/uic/barcode/Encoder.java b/src/main/java/org/uic/barcode/Encoder.java index d971214..e906881 100644 --- a/src/main/java/org/uic/barcode/Encoder.java +++ b/src/main/java/org/uic/barcode/Encoder.java @@ -2,6 +2,7 @@ package org.uic.barcode; import java.io.IOException; import java.security.PrivateKey; +import java.security.Provider; import java.security.PublicKey; import org.uic.barcode.asn1.datatypesimpl.OctetString; @@ -120,6 +121,20 @@ public class Encoder { dynamicFrame.signLevel2(key); } } + + /** + * Signing level 2 of a dynamic bar code + * + * @param key the key + * @param provider - provider of the java security implementation to be used + * @throws Exception the exception + */ + public void signLevel2(PrivateKey key, Provider prov) throws Exception { + if (dynamicFrame != null) { + dynamicFrame.signLevel2(key, prov); + } + } + /** * Sets the level 1 algorithm Is. @@ -193,7 +208,7 @@ public class Encoder { /** * Sign level 1 of a dynamic bar code or a static bar code. * - * @param securityProvider the security provider + * @param securityProvider the security provider (RICS code of the company responsible for the security) * @param key the key * @param signingAlg the signing algorithm (OID) * @param keyId the key id @@ -215,6 +230,33 @@ public class Encoder { } } + /** + * Sign level 1 of a dynamic bar code or a static bar code. + * + * @param securityProvider the security provider (RICS code of the company responsible for the security) + * @param key the key + * @param signingAlg the signing algorithm (OID) + * @param keyId the key id + * @param provider - the provider of the java security implementation + * @throws Exception the exception + */ + public void signLevel1(String securityProvider,PrivateKey key,String signingAlg, String keyId, Provider prov) throws Exception { + if (dynamicFrame != null) { + dynamicFrame.getLevel2SignedData().getLevel1Data().setSecurityProvider(securityProvider); + dynamicFrame.getLevel2SignedData().getLevel1Data().setLevel1SigningAlg(signingAlg); + dynamicFrame.getLevel2SignedData().getLevel1Data().setKeyId(Long.parseLong(keyId)); + dynamicFrame.getLevel2SignedData().signLevel1(key, prov); + } else if (staticFrame != null) { + staticFrame.setSignatureKey(keyId); + staticFrame.setSecurityProvider(securityProvider); + if (staticFrame.getHeaderRecord()!= null && staticFrame.getHeaderRecord().getIssuer() == null) { + staticFrame.getHeaderRecord().setIssuer(securityProvider); + } + staticFrame.signByAlgorithmOID(key,signingAlg,prov); + } + } + + /** * Sets the static header parameter. * -- cgit v1.2.3