You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oltu.apache.org by si...@apache.org on 2010/07/11 16:13:36 UTC

svn commit: r963078 - /incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java

Author: simonetripodi
Date: Sun Jul 11 14:13:36 2010
New Revision: 963078

URL: http://svn.apache.org/viewvc?rev=963078&view=rev
Log:
first checkin of RsaSha1Method class

Added:
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java   (with props)

Added: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java?rev=963078&view=auto
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java (added)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java Sun Jul 11 14:13:36 2010
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.amber.signature.rsa;
+
+import java.security.Signature;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+
+import org.apache.amber.signature.AbstractMethod;
+import org.apache.amber.signature.SignatureException;
+import org.apache.amber.signature.SigningKey;
+import org.apache.amber.signature.VerifyingKey;
+
+/**
+ * RSA-SHA1 Method implementation.
+ *
+ * @version $Id$
+ */
+public final class RsaSha1Method extends AbstractMethod {
+
+    /**
+     * RSA+SHA1 algorithm name.
+     */
+    private static final String RSA_SHA1_ALGORITHM = "SHA1withRSA";
+
+    /**
+     * This method name.
+     */
+    private final static String RSA_SHA1 = "RSA-SHA1";
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getAlgorithm() {
+        return RSA_SHA1;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    protected String calculate(SigningKey signingKey,
+            String tokenSecret,
+            String baseString) throws SignatureException {
+        try {
+            Signature signer = Signature.getInstance(RSA_SHA1_ALGORITHM);
+            signer.initSign(((AbstractRsaSha1Key<RSAPrivateKey>) signingKey).getRsaKey());
+            signer.update(toUTF8Bytes(baseString));
+            byte[] signature = signer.sign();
+
+            return encodeBase64(signature);
+        } catch (Exception e) {
+            // TODO add a meaningful message
+            throw new SignatureException(e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    @SuppressWarnings("unchecked")
+    protected boolean verify(String signature,
+            VerifyingKey verifyingKey,
+            String tokenSecret,
+            String baseString) throws SignatureException {
+        try {
+            Signature verifier = Signature.getInstance(RSA_SHA1_ALGORITHM);
+            verifier.initVerify(((AbstractRsaSha1Key<RSAPublicKey>) verifyingKey).getRsaKey());
+            verifier.update(toUTF8Bytes(baseString));
+
+            return verifier.verify(decodeBase64(signature));
+        } catch (Exception e) {
+            // TODO add a meaningful message
+            throw new SignatureException(e);
+        }
+    }
+
+}

Propchange: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain