Ejemplo n.º 1
0
        // Builds a DNSKEY record from a PublicKey
        // https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
        public static byte[] fromPublicKey(PublicKey key, ARSoft.Tools.Net.Dns.DnsSecAlgorithm alg) // throws DNSSECException
        {
            switch (alg)
            {
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaMd5:
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha1:
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha1Nsec3Sha1:
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha256:
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha512:
                if (!(key is RSAPublicKey))
                {
                    throw new IncompatibleKeyException();
                }

                return(fromRSAPublicKey((RSAPublicKey)key));

            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.Dsa:
            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.DsaNsec3Sha1:
                if (!(key is DSAPublicKey))
                {
                    throw new IncompatibleKeyException();
                }
                return(fromDSAPublicKey((DSAPublicKey)key));

            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EccGost:
                if (!(key is ECPublicKey))
                {
                    throw new IncompatibleKeyException();
                }
                return(fromECGOSTPublicKey((ECPublicKey)key, ECKeyInfo.GOST));

            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EcDsaP256Sha256:
                if (!(key is ECPublicKey))
                {
                    throw new IncompatibleKeyException();
                }
                return(fromECDSAPublicKey((ECPublicKey)key, ECKeyInfo.ECDSA_P256));

            case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EcDsaP384Sha384:
                if (!(key is ECPublicKey))
                {
                    throw new IncompatibleKeyException();
                }
                return(fromECDSAPublicKey((ECPublicKey)key, ECKeyInfo.ECDSA_P384));

            default:
                throw new UnsupportedAlgorithmException(alg);
            }
        } // End Function fromPublicKey
Ejemplo n.º 2
0
        // Converts a KEY/DNSKEY record into a PublicKey
        // https://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml
        public static PublicKey toPublicKey(byte[] keyBytes, ARSoft.Tools.Net.Dns.DnsSecAlgorithm algorithm) // throws DNSSECException
        {
            try
            {
                switch (algorithm)
                {
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaMd5:
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha1:
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha1Nsec3Sha1:
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha256:
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.RsaSha512:
                    return(toRSAPublicKey(keyBytes));

                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.Dsa:
                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.DsaNsec3Sha1:
                    return(toDSAPublicKey(keyBytes));

                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EccGost:
                    return(toECGOSTPublicKey(keyBytes, ECKeyInfo.GOST));

                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EcDsaP256Sha256:
                    return(toECDSAPublicKey(keyBytes, ECKeyInfo.ECDSA_P256));

                case ARSoft.Tools.Net.Dns.DnsSecAlgorithm.EcDsaP384Sha384:
                    return(toECDSAPublicKey(keyBytes, ECKeyInfo.ECDSA_P384));

                default:
                    throw new UnsupportedAlgorithmException(algorithm);
                }
            }
            catch (System.IO.IOException e)
            {
                throw new MalformedKeyException(keyBytes, algorithm, e);
            }
            catch (Org.BouncyCastle.Security.GeneralSecurityException e)
            {
                throw new DNSSECException(e);
            }
        } // End Function toPublicKey
Ejemplo n.º 3
0
 public MalformedKeyException(byte[] r, ARSoft.Tools.Net.Dns.DnsSecAlgorithm algorithm, System.IO.IOException e)
 {
 }
Ejemplo n.º 4
0
 public MalformedKeyException(byte[] r, ARSoft.Tools.Net.Dns.DnsSecAlgorithm algorithm)
 {
 }
Ejemplo n.º 5
0
 public UnsupportedAlgorithmException(ARSoft.Tools.Net.Dns.DnsSecAlgorithm alg)
 {
 }
Ejemplo n.º 6
0
 public KEYBase(byte[] key, ARSoft.Tools.Net.Dns.DnsSecAlgorithm algorithm)
 {
     this.m_key       = key;
     this.m_algorithm = (int)algorithm;
 }