Esempio n. 1
0
        internal Certificate(DigitalSignature digitalSignature, Stream stream)
        {
            if (digitalSignature == null)
            {
                throw new ArgumentNullException("digitalSignature");
            }

            byte[] signature;

            if (digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.EcDsaP521_Sha256)
            {
                signature = EcDsaP521_Sha256.Sign(digitalSignature.PrivateKey, stream);
            }
            else if (digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.Rsa2048_Sha256)
            {
                signature = Rsa2048_Sha256.Sign(digitalSignature.PrivateKey, stream);
            }
            else
            {
                return;
            }

            this.Nickname = digitalSignature.Nickname;
            this.DigitalSignatureAlgorithm = digitalSignature.DigitalSignatureAlgorithm;
            this.PublicKey = digitalSignature.PublicKey;
            this.Signature = signature;
        }
Esempio n. 2
0
        public static string GetSignature(DigitalSignature digitalSignature)
        {
            if (digitalSignature == null || digitalSignature.Nickname == null || digitalSignature.PublicKey == null)
            {
                return(null);
            }

            try
            {
                if (digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.EcDsaP521_Sha256 ||
                    digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.Rsa2048_Sha256)
                {
                    using (BufferStream bufferStream = new BufferStream(_bufferManager))
                    {
                        Signature.WriteString(bufferStream, digitalSignature.Nickname);
                        bufferStream.Write(digitalSignature.PublicKey, 0, digitalSignature.PublicKey.Length);
                        bufferStream.Seek(0, SeekOrigin.Begin);

                        var signature = digitalSignature.Nickname + "@" + NetworkConverter.ToBase64UrlString(Sha256.ComputeHash(bufferStream));
                        return(_signatureCache.GetValue(signature, digitalSignature));
                    }
                }

                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
 public virtual void CreateCertificate(DigitalSignature digitalSignature)
 {
     if (digitalSignature == null)
     {
         this.Certificate = null;
     }
     else
     {
         using (var stream = this.GetCertificateStream())
         {
             this.Certificate = new Certificate(digitalSignature, stream);
         }
     }
 }
Esempio n. 4
0
        public static Stream ToDigitalSignatureStream(DigitalSignature item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                return(Converter.ToStream <DigitalSignature>(item));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 5
0
 public static Stream ToDigitalSignatureStream(DigitalSignature item)
 {
     return(Converter.ToDigitalSignatureStream(item));
 }