SignatureBaseRSA.java revision 0
0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
0N/A */
0N/Apackage com.sun.org.apache.xml.internal.security.algorithms.implementations;
0N/A
0N/A
0N/A
0N/Aimport java.security.InvalidAlgorithmParameterException;
0N/Aimport java.security.InvalidKeyException;
0N/Aimport java.security.Key;
0N/Aimport java.security.NoSuchProviderException;
0N/Aimport java.security.PrivateKey;
0N/Aimport java.security.PublicKey;
0N/Aimport java.security.SecureRandom;
0N/Aimport java.security.Signature;
0N/Aimport java.security.SignatureException;
0N/Aimport java.security.spec.AlgorithmParameterSpec;
0N/A
0N/Aimport com.sun.org.apache.xml.internal.security.algorithms.JCEMapper;
0N/Aimport com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi;
0N/Aimport com.sun.org.apache.xml.internal.security.signature.XMLSignature;
0N/Aimport com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
0N/A
0N/A
0N/A/**
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/Apublic abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
0N/A
0N/A /** {@link java.util.logging} logging facility */
0N/A static java.util.logging.Logger log =
0N/A java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName());
0N/A
0N/A /** @inheritDoc */
0N/A public abstract String engineGetURI();
0N/A
0N/A /** Field algorithm */
0N/A private java.security.Signature _signatureAlgorithm = null;
0N/A
0N/A /**
0N/A * Constructor SignatureRSA
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureBaseRSA() throws XMLSignatureException {
0N/A
0N/A String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
0N/A
0N/A if (true)
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
0N/A String provider=JCEMapper.getProviderId();
0N/A try {
0N/A if (provider==null) {
0N/A this._signatureAlgorithm = Signature.getInstance(algorithmID);
0N/A } else {
0N/A this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
0N/A }
0N/A } catch (java.security.NoSuchAlgorithmException ex) {
0N/A Object[] exArgs = { algorithmID,
0N/A ex.getLocalizedMessage() };
0N/A
0N/A throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
0N/A } catch (NoSuchProviderException ex) {
0N/A Object[] exArgs = { algorithmID,
0N/A ex.getLocalizedMessage() };
0N/A
0N/A throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineSetParameter(AlgorithmParameterSpec params)
0N/A throws XMLSignatureException {
0N/A
0N/A try {
0N/A this._signatureAlgorithm.setParameter(params);
0N/A } catch (InvalidAlgorithmParameterException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected boolean engineVerify(byte[] signature)
0N/A throws XMLSignatureException {
0N/A
0N/A try {
0N/A return this._signatureAlgorithm.verify(signature);
0N/A } catch (SignatureException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
0N/A
0N/A if (!(publicKey instanceof PublicKey)) {
0N/A String supplied = publicKey.getClass().getName();
0N/A String needed = PublicKey.class.getName();
0N/A Object exArgs[] = { supplied, needed };
0N/A
0N/A throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
0N/A exArgs);
0N/A }
0N/A
0N/A try {
0N/A this._signatureAlgorithm.initVerify((PublicKey) publicKey);
0N/A } catch (InvalidKeyException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected byte[] engineSign() throws XMLSignatureException {
0N/A
0N/A try {
0N/A return this._signatureAlgorithm.sign();
0N/A } catch (SignatureException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
0N/A throws XMLSignatureException {
0N/A
0N/A if (!(privateKey instanceof PrivateKey)) {
0N/A String supplied = privateKey.getClass().getName();
0N/A String needed = PrivateKey.class.getName();
0N/A Object exArgs[] = { supplied, needed };
0N/A
0N/A throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
0N/A exArgs);
0N/A }
0N/A
0N/A try {
0N/A this._signatureAlgorithm.initSign((PrivateKey) privateKey,
0N/A secureRandom);
0N/A } catch (InvalidKeyException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineInitSign(Key privateKey) throws XMLSignatureException {
0N/A
0N/A if (!(privateKey instanceof PrivateKey)) {
0N/A String supplied = privateKey.getClass().getName();
0N/A String needed = PrivateKey.class.getName();
0N/A Object exArgs[] = { supplied, needed };
0N/A
0N/A throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
0N/A exArgs);
0N/A }
0N/A
0N/A try {
0N/A this._signatureAlgorithm.initSign((PrivateKey) privateKey);
0N/A } catch (InvalidKeyException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineUpdate(byte[] input) throws XMLSignatureException {
0N/A
0N/A try {
0N/A this._signatureAlgorithm.update(input);
0N/A } catch (SignatureException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineUpdate(byte input) throws XMLSignatureException {
0N/A
0N/A try {
0N/A this._signatureAlgorithm.update(input);
0N/A } catch (SignatureException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineUpdate(byte buf[], int offset, int len)
0N/A throws XMLSignatureException {
0N/A
0N/A try {
0N/A this._signatureAlgorithm.update(buf, offset, len);
0N/A } catch (SignatureException ex) {
0N/A throw new XMLSignatureException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected String engineGetJCEAlgorithmString() {
0N/A return this._signatureAlgorithm.getAlgorithm();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected String engineGetJCEProviderName() {
0N/A return this._signatureAlgorithm.getProvider().getName();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineSetHMACOutputLength(int HMACOutputLength)
0N/A throws XMLSignatureException {
0N/A throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A protected void engineInitSign(
0N/A Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
0N/A throws XMLSignatureException {
0N/A throw new XMLSignatureException(
0N/A "algorithms.CannotUseAlgorithmParameterSpecOnRSA");
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSASHA1
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSASHA1 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSASHA1
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSASHA1() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSASHA256
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSASHA256 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSASHA256
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSASHA256() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSASHA384
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSASHA384 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSASHA384
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSASHA384() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSASHA512
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSASHA512 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSASHA512
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSASHA512() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSARIPEMD160
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSARIPEMD160
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSARIPEMD160() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Class SignatureRSAMD5
0N/A *
0N/A * @author $Author: raul $
0N/A */
0N/A public static class SignatureRSAMD5 extends SignatureBaseRSA {
0N/A
0N/A /**
0N/A * Constructor SignatureRSAMD5
0N/A *
0N/A * @throws XMLSignatureException
0N/A */
0N/A public SignatureRSAMD5() throws XMLSignatureException {
0N/A super();
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String engineGetURI() {
0N/A return XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5;
0N/A }
0N/A }
0N/A}