diff options
author | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-06-28 17:28:50 +0200 |
---|---|---|
committer | CGantert345 <57003061+CGantert345@users.noreply.github.com> | 2021-06-28 17:28:50 +0200 |
commit | 6eebf3f29b9658a4e74ab1d1f90146c8e029c736 (patch) | |
tree | 06acac1ffecee6ff0cdeaed77397312b0db0e8eb /src/main/java/org/uic/barcode/staticFrame | |
parent | - initial implementation of FCB version 3.0.0 - !!Tests still missing!! (diff) | |
download | UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar.gz UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar.bz2 UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar.lz UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar.xz UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.tar.zst UIC-barcode-6eebf3f29b9658a4e74ab1d1f90146c8e029c736.zip |
Diffstat (limited to 'src/main/java/org/uic/barcode/staticFrame')
-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.
*
|