public override byte[] Compose() { var name = base.Compose(); var bl = new BinaryList() .AddUInt8((byte)name.Length) .AddUInt8Array(name) .AddUInt8Array(ReturnType.Compose()) .AddUInt8((byte)Arguments.Length); for (var i = 0; i < Arguments.Length; i++) { bl.AddUInt8Array(Arguments[i].Compose()); } if (Annotation != null) { var exp = DC.ToBytes(Annotation); bl.AddInt32(exp.Length) .AddUInt8Array(exp); bl.InsertUInt8(0, Inherited ? (byte)0x90 : (byte)0x10); } else { bl.InsertUInt8(0, Inherited ? (byte)0x80 : (byte)0x0); } return(bl.ToArray()); }
public DomainCertificate(ulong id, string domain, CACertificate authority, DateTime issueDate, DateTime expireDate, HashFunctionType hashFunction = HashFunctionType.SHA1, uint ip = 0, byte[] ip6 = null) : base(id, issueDate, expireDate, hashFunction) { // assign type var cr = new BinaryList(); // id cr.AddUInt64(id); // ip this.ip = ip; this.ip6 = ip6; cr.AddUInt32(ip); if (ip6?.Length == 16) { cr.AddUInt8Array(ip6); } else { cr.AddUInt8Array(new byte[16]); } cr.AddDateTime(issueDate) .AddDateTime(expireDate); // domain this.domain = domain; cr.AddUInt8((byte)(domain.Length)) .AddUInt8Array(Encoding.ASCII.GetBytes(domain)); // CA this.caName = authority.Name; cr.AddUInt8((byte)(authority.Name.Length)) .AddUInt8Array(Encoding.ASCII.GetBytes(authority.Name)); this.authorityName = authority.Name; // CA Index //co.KeyIndex = authority.KeyIndex; this.caId = authority.Id; cr.AddUInt64(caId); // public key rsa = RSA.Create();// new RSACryptoServiceProvider(2048); rsa.KeySize = 2048; RSAParameters dRSAKey = rsa.ExportParameters(true); cr.AddUInt8((byte)dRSAKey.Exponent.Length) .AddUInt8Array(dRSAKey.Exponent) .AddUInt16((ushort)dRSAKey.Modulus.Length) .AddUInt8Array(dRSAKey.Modulus); publicRawData = cr.ToArray(); // private key this.privateRawData = DC.Merge(dRSAKey.D, dRSAKey.DP, dRSAKey.DQ, dRSAKey.InverseQ, dRSAKey.P, dRSAKey.Q); this.signature = authority.Sign(publicRawData); }
public UserCertificate(ulong id, string username, DomainCertificate domainCertificate, DateTime issueDate, DateTime expireDate, HashFunctionType hashFunction = HashFunctionType.SHA1, uint ip = 0, byte[] ip6 = null) : base(id, issueDate, expireDate, hashFunction) { // assign type var cr = new BinaryList(); //id cr.AddUInt64(id); // ip this.ip = ip; this.ip6 = ip6; cr.AddUInt32(ip); if (ip6?.Length == 16) { cr.AddUInt8Array(ip6); } else { cr.AddUInt8Array(new byte[16]); } // dates this.issueDate = DateTime.UtcNow; this.expireDate = expireDate; cr.AddDateTime(issueDate) .AddDateTime(expireDate); // domain this.domainId = domainCertificate.Id; cr.AddUInt64(domainCertificate.Id); this.domain = domainCertificate.Domain; cr.AddUInt8((byte)domainCertificate.Domain.Length) .AddUInt8Array(Encoding.ASCII.GetBytes(domainCertificate.Domain)); // username this.username = username; cr.AddUInt8((byte)(username.Length)) .AddUInt8Array(Encoding.ASCII.GetBytes(username)); // hash function (SHA1) cr.AddUInt8((byte)((byte)hashFunction << 4));// (byte)0x10); // public key rsa = RSA.Create();// new RSACryptoServiceProvider(2048); rsa.KeySize = 2048; // write public certificate file var key = rsa.ExportParameters(true); publicRawData = new BinaryList().AddUInt8((byte)key.Exponent.Length) .AddUInt8Array(key.Exponent) .AddUInt16((ushort)key.Modulus.Length) .AddUInt8Array(key.Modulus).ToArray(); // sign it this.signature = domainCertificate.Sign(publicRawData); // store private info privateRawData = DC.Merge(key.D, key.DP, key.DQ, key.InverseQ, key.P, key.Q, signature); }