Beispiel #1
0
 /**
  * The default constructor.
  *
  * @param encryptionAlgorithm
  *            the encryption algorithm
  * @param digestAlgorithm
  *            the digest algorithm
  * @param mgf
  *            the mask generation function
  */
 SignatureAlgorithm(EncryptionAlgorithm encryptionAlgorithm, DigestAlgorithm digestAlgorithm,
                    MaskGenerationFunction maskGenerationFunction)
 {
     this.EncryptionAlgorithm    = encryptionAlgorithm;
     this.DigestAlgorithm        = digestAlgorithm;
     this.MaskGenerationFunction = maskGenerationFunction;
 }
Beispiel #2
0
        /**
         * Returns the digest algorithm associated to the given XML url or the default
         * one if the algorithm does not exist.
         *
         * @param xmlName
         *                     The XML representation of the digest algorithm
         * @param defaultValue
         *                     The default value for the {@code DigestAlgorithm}
         * @return the corresponding {@code DigestAlgorithm} or the default value
         */
        public static DigestAlgorithm ForXML(string xmlName, DigestAlgorithm defaultValue)
        {
            DigestAlgorithm algorithm = Registry.XML_ALGORITHMS[xmlName];

            if (algorithm == null)
            {
                return(defaultValue);
            }
            return(algorithm);
        }
Beispiel #3
0
        /**
         * Returns the digest algorithm associated to the given XML url.
         *
         * @param xmlName
         *                the algorithm uri
         * @return the digest algorithm linked to the given uri
         * @throws IllegalArgumentException
         *                                  if the uri doesn't match any digest
         *                                  algorithm
         */
        public static DigestAlgorithm ForXML(string xmlName)
        {
            DigestAlgorithm algorithm = Registry.XML_ALGORITHMS[xmlName];

            if (algorithm == null)
            {
                throw new ArgumentException("Unsupported algorithm: " + xmlName, nameof(xmlName));
            }
            return(algorithm);
        }
Beispiel #4
0
        /**
         * Returns the digest algorithm associated to the given OID.
         *
         * @param oid
         *            the algorithm oid
         * @return the digest algorithm linked to the oid
         * @throws IllegalArgumentException
         *                                  if the oid doesn't match any digest
         *                                  algorithm
         */
        public static DigestAlgorithm ForOID(string oid)
        {
            DigestAlgorithm algorithm = Registry.OID_ALGORITHMS[oid];

            if (algorithm == null)
            {
                throw new ArgumentException("Unsupported algorithm: " + oid, nameof(oid));
            }
            return(algorithm);
        }
Beispiel #5
0
        /**
         * Returns the digest algorithm associated to the given name.
         *
         * @param name
         *                     the algorithm name
         * @param defaultValue
         *                     The default value for the {@code DigestAlgorithm}
         * @return the corresponding {@code DigestAlgorithm} or the default value
         */
        public static DigestAlgorithm ForName(string name, DigestAlgorithm defaultValue)
        {
            DigestAlgorithm algorithm = Registry.ALGORITHMS[name];

            if (algorithm == null)
            {
                return(defaultValue);
            }
            return(algorithm);
        }
Beispiel #6
0
        /**
         * Returns the digest algorithm associated to the given name.
         *
         * @param name
         *             the algorithm name
         * @return the digest algorithm linked to the given name
         * @throws IllegalArgumentException
         *                                  if the given name doesn't match any
         *                                  algorithm
         */
        public static DigestAlgorithm ForName(string name)
        {
            DigestAlgorithm algorithm = Registry.ALGORITHMS[name];

            if (algorithm == null)
            {
                throw new ArgumentException("Unsupported algorithm: " + name, nameof(name));
            }
            return(algorithm);
        }
Beispiel #7
0
 /**
  * The default constructor.
  *
  * @param encryptionAlgorithm
  *            the encryption algorithm
  * @param digestAlgorithm
  *            the digest algorithm
  */
 private SignatureAlgorithm(EncryptionAlgorithm encryptionAlgorithm, DigestAlgorithm digestAlgorithm)
 {
     this.EncryptionAlgorithm    = encryptionAlgorithm;
     this.DigestAlgorithm        = digestAlgorithm;
     this.MaskGenerationFunction = null;
 }
Beispiel #8
0
        /**
         * For given encryption algorithm and digest algorithm this function returns the signature algorithm.
         *
         * @param encryptionAlgorithm
         *            the encryption algorithm
         * @param digestAlgorithm
         *            the digest algorithm
         * @param mgf
         *            the mask generation function
         * @return the corresponding combination of both algorithms
         */
        public static SignatureAlgorithm GetAlgorithm(EncryptionAlgorithm encryptionAlgorithm, DigestAlgorithm digestAlgorithm,
                                                      MaskGenerationFunction?mgf)
        {
            StringBuilder sb = new StringBuilder();

            if (digestAlgorithm != null)
            {
                sb.Append(digestAlgorithm.Name);
            }
            else
            {
                sb.Append("NONE");
            }
            sb.Append("with");
            sb.Append(encryptionAlgorithm.Name);
            if (mgf != null)
            {
                sb.Append("andMGF1");
            }
            return(JAVA_ALGORITHMS[sb.ToString()]);
        }
Beispiel #9
0
 /**
  * For given encryption algorithm and digest algorithm this function returns the signature algorithm.
  *
  * @param encryptionAlgorithm
  *            the encryption algorithm
  * @param digestAlgorithm
  *            the digest algorithm
  * @return the corresponding combination of both algorithms
  */
 public static SignatureAlgorithm GetAlgorithm(EncryptionAlgorithm encryptionAlgorithm, DigestAlgorithm digestAlgorithm)
 {
     return(GetAlgorithm(encryptionAlgorithm, digestAlgorithm, null));
 }