コード例 #1
0
        // GET: api/OtherKeys
        public IHttpActionResult Get(int count = 20, int length = 64, string encoding = "Hex")
        {
            var encodingFlag = (ChaosHelper.KeyEncoding)Enum.Parse(typeof(ChaosHelper.KeyEncoding), encoding);

            if (count < 1 || count > 50)
            {
                count = 20;
            }
            if (length < 16 || length > 8192)
            {
                length = 64;
            }

            var output = new StringBuilder();

            for (int i = 0; i < count; i++)
            {
                output.AppendLine(ChaosHelper.GenerateKey(length, encodingFlag));
            }

            return(Ok(output.ToString()));
        }
コード例 #2
0
        // GET: api/MachineKey
        public IHttpActionResult Get(string validation = "HMACSHA256", string decryption = "AES256")
        {
            int validationKeyLength, decryptionKeyLength;

            switch (validation)
            {
            case "MD5":
                validationKeyLength = 128;
                break;

            case "SHA1":
                validationKeyLength = 160;
                break;

            case "3DES":
                validationKeyLength = 192;
                break;

            case "AES":
            case "HMACSHA256":
                validationKeyLength = 256;
                break;

            case "HMACSHA384":
                validationKeyLength = 384;
                break;

            case "HMACSHA512":
                validationKeyLength = 512;
                break;

            default:
                return(BadRequest("Invalid parameter 'validation'"));
            }

            switch (decryption)
            {
            case "DES":
                decryptionKeyLength = 64;
                break;

            case "3DES":
                decryptionKeyLength = 192;
                break;

            case "AES128":
                decryption          = "AES";
                decryptionKeyLength = 128;
                break;

            case "AES192":
                decryption          = "AES";
                decryptionKeyLength = 192;
                break;

            case "AES256":
                decryption          = "AES";
                decryptionKeyLength = 256;
                break;

            default:
                return(BadRequest("Invalid parameter 'decryption'"));
            }

            var output = string.Format(XML_CODE,
                                       validation,
                                       decryption,
                                       ChaosHelper.GenerateKey(validationKeyLength / 8, ChaosHelper.KeyEncoding.UpperHex),
                                       ChaosHelper.GenerateKey(decryptionKeyLength / 8, ChaosHelper.KeyEncoding.UpperHex));

            return(Ok(output));
        }