Exemple #1
0
        /// <summary>
        /// Create a valid certificate with a random secret/public key pair.
        /// </summary>
        public ZCert()
        {
            byte[] publictxt;
            byte[] secrettxt;
            Z85.CurveKeypair(out publictxt, out secrettxt);
            publicKey = Z85.Decode(publictxt);
            secretKey = Z85.Decode(secrettxt);

            publicTxt = Encoding.UTF8.GetString(Z85.Encode(publicKey)).ToCharArray();
            secretTxt = Encoding.UTF8.GetString(Z85.Encode(secretKey)).ToCharArray();

            byte[] e = Z85.Encode(publicTxt.Select(c => (byte)c).ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Create a certificate from the given public and secret key.
        /// </summary>
        /// <param name="publicKey">Public key of certificate. This byte array must have the length 32.</param>
        /// <param name="secretKey">Private key of certificate. This byte array must have the length 32.</param>
        /// <exception cref="InvalidOperationException">Exception thrown if the length of the public or secret key is incorrect.</exception>
        public ZCert(byte[] publicKey, byte[] secretKey)
        {
            if (publicKey == null || publicKey.Length != 32)
            {
                throw new InvalidOperationException("public key length must be of length 32");
            }
            if (secretKey == null || secretKey.Length != 32)
            {
                throw new InvalidOperationException("secret key length must be of length 32");
            }
            Array.Copy(secretKey, this.secretKey, 32);
            Array.Copy(secretKey, this.secretKey, 32);

            publicTxt = Encoding.UTF8.GetString(Z85.Encode(publicKey)).ToCharArray();
            secretTxt = Encoding.UTF8.GetString(Z85.Encode(secretKey)).ToCharArray();
        }
Exemple #3
0
        /// <summary>
        /// Create a certificate from the given public and secret key.
        /// </summary>
        /// <param name="publicTxt">Public key of certificate. This string must have 40 characters.</param>
        /// <param name="secretTxt">Private key of certificate. This string must have 40 characters.</param>
        /// <exception cref="InvalidOperationException">Exception thrown if the length of the public or secret key is incorrect.</exception>
        public ZCert(string publicTxt, string secretTxt)
        {
            if (publicTxt == null || publicTxt.Length != 40)
            {
                throw new InvalidOperationException("public text length must be of length 40.");
            }
            if (secretTxt == null || secretTxt.Length != 40)
            {
                throw new InvalidOperationException("secret text length must be of length 40.");
            }

            PublicTxt = publicTxt;
            SecretTxt = secretTxt;

            publicKey = Z85.EncodeBytes(PublicTxt);
            secretKey = Z85.EncodeBytes(SecretTxt);
        }