diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-06-29 16:26:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 16:26:36 +0200 |
commit | 27d114203f6edaf8aea75ee710bd87f32d79f003 (patch) | |
tree | 794e40b39e154adef8e471ab8774c8a68bd3e434 /src/main/java/org/uic/barcode/staticFrame/StaticFrame.java | |
parent | Delete uicBarcodeFCBv2.0.asn (diff) | |
parent | - test for FCB version 3 (diff) | |
download | UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar.gz UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar.bz2 UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar.lz UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar.xz UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.tar.zst UIC-barcode-27d114203f6edaf8aea75ee710bd87f32d79f003.zip |
Diffstat (limited to '')
-rw-r--r-- | src/main/java/org/uic/barcode/staticFrame/StaticFrame.java | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java index 2759bf0..8dc1adb 100644 --- a/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java +++ b/src/main/java/org/uic/barcode/staticFrame/StaticFrame.java @@ -677,6 +677,39 @@ public class StaticFrame { sig.update(getDataForSignature());
return sig.verify(this.getSignature());
}
+
+ /**
+ * Verify the signature
+ *
+ * Note: an appropriate security provider (e.g. BC) must be registered before
+ *
+ * @param key the key
+ * @param singningAlg the Object ID of the signing algorithm
+ * @param a dedicated security provider to validate the signature
+ * @return true, if successful
+ * @throws InvalidKeyException the invalid key exception
+ * @throws NoSuchAlgorithmException the no such algorithm exception
+ * @throws SignatureException the signature exception
+ * @throws IllegalArgumentException the illegal argument exception
+ * @throws UnsupportedOperationException the unsupported operating exception
+ * @throws EncodingFormatException
+ * @throws IOException
+ */
+ 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 (algo == null) {
+ throw new NoSuchAlgorithmException("No service for algorithm found: " + signingAlg);
+ }
+ Signature sig = Signature.getInstance(algo);
+ sig.initVerify(key);
+ sig.update(getDataForSignature());
+ return sig.verify(this.getSignature());
+ }
/**
* Sign the contained data block.
@@ -695,14 +728,51 @@ public class StaticFrame { public void signByAlgorithmOID(PrivateKey key,String signingAlg) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, IOException, EncodingFormatException {
//find the algorithm name for the signature OID
String algo = null;
+ algo = getAlgo(signingAlg);
+ if (algo == null) {
+ throw new NoSuchAlgorithmException("No service for algorthm found: " + signingAlg);
+ }
+ Signature sig = Signature.getInstance(algo);
+ sig.initSign(key);
+ signedData = getDataForSignature();
+ sig.update(signedData);
+ signature = sig.sign();
+ }
+
+ private String getAlgo(String signingAlg) {
Provider[] provs = Security.getProviders();
for (Provider prov : provs) {
Service service = prov.getService("Signature",signingAlg);
if (service != null) {
- algo = service.getAlgorithm();
- break;
+ return service.getAlgorithm();
}
}
+ return null;
+ }
+
+
+
+ /**
+ * Sign the contained data block.
+ *
+ * Note: an appropriate security provider (e.g. BC) must be registered before
+ *
+ * @param key the key
+ * @param singningAlg the Object ID of the signing algorithm
+ * @return
+ * @throws NoSuchAlgorithmException the no such algorithm exception
+ * @throws InvalidKeyException the invalid key exception
+ * @throws SignatureException the signature exception
+ * @throws EncodingFormatException
+ * @throws IOException
+ */
+ public void signByAlgorithmOID(PrivateKey key,String signingAlg, Provider prov) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, 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 (algo == null) {
throw new NoSuchAlgorithmException("No service for algorthm found: " + signingAlg);
}
@@ -713,6 +783,7 @@ public class StaticFrame { signature = sig.sign();
}
+
/**
* Sign the contained data block.
*
|