diff --git a/source/nanoFramework.System.Net/X509Certificates/X509Certificate.cs b/source/nanoFramework.System.Net/X509Certificates/X509Certificate.cs index e130236..b6da0b3 100644 --- a/source/nanoFramework.System.Net/X509Certificates/X509Certificate.cs +++ b/source/nanoFramework.System.Net/X509Certificates/X509Certificate.cs @@ -91,7 +91,16 @@ public X509Certificate(byte[] certificate, string password) /// public X509Certificate(string certificate) { - _certificate = Encoding.UTF8.GetBytes(certificate); + var tempCertificate = Encoding.UTF8.GetBytes(certificate); + + ////////////////////////////////////////////// + // because this is parsing from a string // + // we need to keep the terminator // + ////////////////////////////////////////////// + _certificate = new byte[tempCertificate.Length + 1]; + Array.Copy(tempCertificate, _certificate, tempCertificate.Length); + _certificate[_certificate.Length - 1] = 0; + _password = ""; ParseCertificate(_certificate, _password, ref _issuer, ref _subject, ref _effectiveDate, ref _expirationDate); @@ -108,10 +117,19 @@ public X509Certificate(string certificate) /// public X509Certificate(string certificate, string password) { - _certificate = Encoding.UTF8.GetBytes(certificate); _password = password; - ParseCertificate(Encoding.UTF8.GetBytes(certificate), _password, ref _issuer, ref _subject, ref _effectiveDate, ref _expirationDate); + var tempCertificate = Encoding.UTF8.GetBytes(certificate); + + ////////////////////////////////////////////// + // because this is parsing from a string // + // we need to keep the terminator // + ////////////////////////////////////////////// + _certificate = new byte[tempCertificate.Length + 1]; + Array.Copy(tempCertificate, _certificate, tempCertificate.Length); + _certificate[_certificate.Length - 1] = 0; + + ParseCertificate(_certificate, _password, ref _issuer, ref _subject, ref _effectiveDate, ref _expirationDate); } ///