From b71102bec28087ea3514f54af81741fa48502ccc Mon Sep 17 00:00:00 2001
From: tkellner <tkellner@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>
Date: Tue, 4 Jun 2013 12:50:24 +0000
Subject: Enable different hashing algorithms for use with SWCard

git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@1185 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
---
 smcc/src/main/java/at/gv/egiz/smcc/SWCard.java | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

(limited to 'smcc')

diff --git a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java
index 81b347c3..a896c9a1 100644
--- a/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java
+++ b/smcc/src/main/java/at/gv/egiz/smcc/SWCard.java
@@ -375,7 +375,28 @@ public class SWCard implements SignatureCard {
     }
 
     String algorithm = privateKey.getAlgorithm();
-    algorithm = "SHA1with" + algorithm;
+
+    if (algorithm.equals("RSA")) {
+      if (alg == null ||
+          "http://www.w3.org/2000/09/xmldsig#rsa-sha1".equals(alg)) {
+        algorithm = "SHA1withRSA";
+      } else if (
+          "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256".equals(alg)) {
+          algorithm = "SHA256withRSA";
+      }
+    } else if (algorithm.equals("ECDSA")) {
+      if (alg == null ||
+          "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1".equals(alg)) {
+          algorithm = "SHA1withECDSA";
+      } else if (
+          "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256".equals(alg)) {
+          algorithm = "SHA256withECDSA";
+      } else if (
+          "http://www.w3.org/2007/05/xmldsig-more#ecdsa-ripemd160".equals(alg)) {
+          algorithm = "RIPEMD160withECDSA";
+      }
+    }
+
     try {
       Signature signature = Signature.getInstance(algorithm);
       signature.initSign(privateKey);
-- 
cgit v1.2.3