Hash Generator (Independent Publisher) (#2872)
* Revert "Merge branch 'microsoft:dev' into dev" This reverts commit096a7c3199
, reversing changes made tocb0948670f
. * Revert "Merge branch 'microsoft:dev' into dev" This reverts commitcb0948670f
, reversing changes made todc26e8a026
. * Revert "Revert "Merge branch 'microsoft:dev' into dev"" This reverts commit01764d0a6d
. * Revert "Revert "Merge branch 'microsoft:dev' into dev"" This reverts commita3f086ef0f
. * Add files via upload * Revert "Add files via upload" This reverts commiteeff7b7a02
. * Add files via upload * Delete independent-publisher-connectors/FileIO directory * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Revert "Add files via upload" This reverts commit1d85506958
. * Add files via upload * Update readme.md * Update readme.md * Update apiDefinition.swagger.json * Update apiProperties.json * Update apiProperties.json
This commit is contained in:
Родитель
8698bc7a36
Коммит
3305031493
|
@ -0,0 +1,123 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Hash Generator",
|
||||
"description": "This hash generator allows you to generate hashes from your input string. You can choose between SHA1, SHA256, SHA512 and MD5.",
|
||||
"version": "1.0",
|
||||
"contact": {
|
||||
"name": "Troy Taylor",
|
||||
"url": "https://www.hitachisolutions.com",
|
||||
"email": "ttaylor@hitachisolutions.com"
|
||||
}
|
||||
},
|
||||
"host": "powerautomate.microsoft.com",
|
||||
"basePath": "/",
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/": {
|
||||
"post": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "default",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hash": {
|
||||
"type": "string",
|
||||
"description": "The hash.",
|
||||
"title": "Hash"
|
||||
},
|
||||
"valueToHash": {
|
||||
"type": "string",
|
||||
"description": "The value hashed.",
|
||||
"title": "Value To Hash"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Generate Hash",
|
||||
"description": "Generate a hash from the given string.",
|
||||
"operationId": "Hash",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"string": {
|
||||
"type": "string",
|
||||
"description": "The string to be hashed.",
|
||||
"title": "String"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The hash type.",
|
||||
"title": "Hash Type",
|
||||
"enum": [
|
||||
"sha1",
|
||||
"sha256",
|
||||
"sha512",
|
||||
"md5"
|
||||
],
|
||||
"x-ms-enum-values": [
|
||||
{
|
||||
"displayName": "SHA1",
|
||||
"value": "sha1"
|
||||
},
|
||||
{
|
||||
"displayName": "SHA256",
|
||||
"value": "sha256"
|
||||
},
|
||||
{
|
||||
"displayName": "SHA512",
|
||||
"value": "sha512"
|
||||
},
|
||||
{
|
||||
"displayName": "MD5",
|
||||
"value": "md5"
|
||||
}
|
||||
],
|
||||
"default": "sha1"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"string"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {},
|
||||
"parameters": {},
|
||||
"responses": {},
|
||||
"securityDefinitions": {},
|
||||
"security": [],
|
||||
"tags": [],
|
||||
"x-ms-connector-metadata": [
|
||||
{
|
||||
"propertyName": "Website",
|
||||
"propertyValue": "https://www.troystaylor.com/"
|
||||
},
|
||||
{
|
||||
"propertyName": "Privacy policy",
|
||||
"propertyValue": "https://www.troystaylor.com/"
|
||||
},
|
||||
{
|
||||
"propertyName": "Categories",
|
||||
"propertyValue": "Security"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"properties": {
|
||||
"connectionParameters": {},
|
||||
"iconBrandColor": "#da3b01",
|
||||
"scriptOperations": [
|
||||
"Hash"
|
||||
],
|
||||
"capabilities": [],
|
||||
"policyTemplateInstances": [],
|
||||
"publisher": "Troy Taylor, Jeffrey Irwin, Ramiro Melgoza",
|
||||
"stackOwner": "Troy Taylor, Jeffrey Irwin, Ramiro Melgoza"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
# Hash Generator
|
||||
This hash generator allows you to generate hashes from your input string. You can choose between SHA1, SHA256, SHA512 and MD5. The hash is generated using custom code and does not connect to a 3rd party service. The custom code was started with the example from [Maksym Martynov's post](https://www.linkedin.com/pulse/powerautomate-dummy-custom-code-connector-maksym-martynov).
|
||||
|
||||
## Publisher: Troy Taylor, Jeffrey Irwin, Ramiro Melgoza
|
||||
|
||||
## Prerequisites
|
||||
There are no prerequisites needed for this service.
|
||||
|
||||
## Obtaining Credentials
|
||||
There are no credentials needed for this service.
|
||||
|
||||
## Supported Operations
|
||||
### Generate Hash
|
||||
Generate a hash from the given string.
|
||||
|
||||
## Known Issues and Limitations
|
||||
There are no known issues at this time.
|
|
@ -0,0 +1,95 @@
|
|||
public class Script : ScriptBase
|
||||
{
|
||||
public override async Task<HttpResponseMessage> ExecuteAsync()
|
||||
{
|
||||
JObject json = JObject.Parse(await this.Context.Request.Content.ReadAsStringAsync());
|
||||
string method = json.GetValue("type").ToString();
|
||||
string valueToHash = json.GetValue("string").ToString();
|
||||
string hashedValue = Hash(valueToHash, method);
|
||||
|
||||
var responseContent = new JObject
|
||||
{
|
||||
["hash"] = hashedValue,
|
||||
["valueToHash"] = valueToHash
|
||||
};
|
||||
|
||||
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
|
||||
|
||||
response.Content = CreateJsonContent(responseContent.ToString());
|
||||
return response;
|
||||
}
|
||||
|
||||
static string Hash(string input, string method) =>
|
||||
method switch
|
||||
{
|
||||
"md5" => CreateMD5(input),
|
||||
"sha1" => CreateSHA1(input),
|
||||
"sha256" => CreateSHA256(input),
|
||||
"sha512" => CreateSHA512(input),
|
||||
_ => CreateSHA1(input)
|
||||
};
|
||||
|
||||
public static string CreateMD5(string input)
|
||||
{
|
||||
using (MD5 md5 = MD5.Create())
|
||||
{
|
||||
byte[] hashBytes = md5.ComputeHash(Encoding.Unicode.GetBytes(input));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateSHA1(string input)
|
||||
{
|
||||
using (SHA1Managed sha1 = new SHA1Managed())
|
||||
{
|
||||
var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
var sb = new StringBuilder(hash.Length * 2);
|
||||
|
||||
foreach (byte b in hash)
|
||||
{
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateSHA256(string input)
|
||||
{
|
||||
using (SHA256Managed sha256 = new SHA256Managed())
|
||||
{
|
||||
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
var sb = new StringBuilder(hash.Length * 2);
|
||||
|
||||
foreach (byte b in hash)
|
||||
{
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string CreateSHA512(string input)
|
||||
{
|
||||
using (SHA512Managed sha512 = new SHA512Managed())
|
||||
{
|
||||
var hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
var sb = new StringBuilder(hash.Length * 2);
|
||||
|
||||
foreach (byte b in hash)
|
||||
{
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче