[Azure] Azure Logic App - 使用 Inline Code 製作 Base64 Decode + XOR 解密

2021-01-24

上一篇文章 說到 Azure Logic App - 使用 Inline Code 製作 Base64 Encode + XOR 加密 ,為何沒有寫解密呢,因為其實因為我工作上沒有用到在加上 Azure Lgoic App 的 Inline code  只能寫 1024字,所以我那時候就沒寫了,不過覺得事情做一半,趁今天假日我就把他補上吧..

前情提要

關於加密的部分請參考 :  

1. 別忘記 如果你要用 Inline Code 必須要開啟 Integration Account

2. 再來就是負責將字串解密用的 Inline Code Javascript Code

function sf(r){return String.fromCharCode(r)} var Base64={_KS:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",decode:function(r){var e,t,o,c,a,d,h="",n=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");n<r.length;)e=this._KS.indexOf(r.charAt(n++))<<2|(c=this._KS.indexOf(r.charAt(n++)))>>4,t=(15&c)<<4|(a=this._KS.indexOf(r.charAt(n++)))>>2,o=(3&a)<<6|(d=this._KS.indexOf(r.charAt(n++))),h+=sf(e),64!=a&&(h+=sf(t)),64!=d&&(h+=sf(o));return h=Base64._decode(h)},_decode:function(r){for(var e="",t=0,o=c1=c2=0;t<r.length;)(o=r.charCodeAt(t))<128?(e+=sf(o),t++):o>191&&o<224?(c2=r.charCodeAt(t+1),e+=sf((31&o)<<6|63&c2),t+=2):(c2=r.charCodeAt(t+1),c3=r.charCodeAt(t+2),e+=sf((15&o)<<12|(63&c2)<<6|63&c3),t+=3);return e}}; function XD(r,e){r=Base64.decode(r);for(var o=Array.from(e),t=[],a=0;a<r.length;a++){var n=r.charCodeAt(a)^o[a%o.length].charCodeAt(0);t.push(sf(n))}var c=t.join("");return Base64.decode(c)} return XD(workflowContext.trigger.outputs.body.Content,'salt1234');

3. 呼叫端的 C# code .

var url="https://prod-27.southeastasia.logic.azure.com:443/workflows/c8f244e4392442aaaf28c707a0c4b117/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=1zOne85ffXnBFplwkuJKTtqyPlgmqBmkKP-ov_9tF7A"; var client = new RestSharp.RestClient(); var request = new RestSharp.RestRequest(url, RestSharp.Method.POST); string jsonToSend = "{\"Content\":\"RhMFBwd5XllGLQUABEJSfCEmVQFTZXtbAi0pSQ==\"}"; request.AddParameter("application/json; charset=utf-8", jsonToSend, RestSharp.ParameterType.RequestBody); request.RequestFormat = RestSharp.DataFormat.Json; try { var c = client.ExecuteAsPost(request, "POST"); Response.Write(c.Content); } catch (Exception error) { // Log }

4. 所有的 Azure Logic App Code:

{ &quot;definition&quot;: { &quot;$schema&quot;: &quot;https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#&quot;, &quot;actions&quot;: { &quot;JS_B64XOR&quot;: { &quot;inputs&quot;: { &quot;code&quot;: &quot;function sf(r){return String.fromCharCode(r)}\r\nvar Base64={_KS:\&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\&quot;,decode:function(r){var e,t,o,c,a,d,h=\&quot;\&quot;,n=0;for(r=r.replace(/[^A-Za-z0-9\\+\\/\\=]/g,\&quot;\&quot;);n&lt;r.length;)e=this._KS.indexOf(r.charAt(n++))&lt;&lt;2|(c=this._KS.indexOf(r.charAt(n++)))&gt;&gt;4,t=(15&amp;c)&lt;&lt;4|(a=this._KS.indexOf(r.charAt(n++)))&gt;&gt;2,o=(3&amp;a)&lt;&lt;6|(d=this._KS.indexOf(r.charAt(n++))),h+=sf(e),64!=a&amp;&amp;(h+=sf(t)),64!=d&amp;&amp;(h+=sf(o));return h=Base64._decode(h)},_decode:function(r){for(var e=\&quot;\&quot;,t=0,o=c1=c2=0;t&lt;r.length;)(o=r.charCodeAt(t))&lt;128?(e+=sf(o),t++):o&gt;191&amp;&amp;o&lt;224?(c2=r.charCodeAt(t+1),e+=sf((31&amp;o)&lt;&lt;6|63&amp;c2),t+=2):(c2=r.charCodeAt(t+1),c3=r.charCodeAt(t+2),e+=sf((15&amp;o)&lt;&lt;12|(63&amp;c2)&lt;&lt;6|63&amp;c3),t+=3);return e}};\r\nfunction XD(r,e){r=Base64.decode(r);for(var o=Array.from(e),t=[],a=0;a&lt;r.length;a++){var n=r.charCodeAt(a)^o[a%o.length].charCodeAt(0);t.push(sf(n))}var c=t.join(\&quot;\&quot;);return Base64.decode(c)}\r\nreturn XD(workflowContext.trigger.outputs.body.Content,&#39;salt1234&#39;);&quot; }, &quot;runAfter&quot;: {}, &quot;type&quot;: &quot;JavaScriptCode&quot; }, &quot;Response&quot;: { &quot;inputs&quot;: { &quot;body&quot;: &quot;@outputs(&#39;JS_B64XOR&#39;)?[&#39;body&#39;]&quot;, &quot;statusCode&quot;: 200 }, &quot;kind&quot;: &quot;Http&quot;, &quot;runAfter&quot;: { &quot;JS_B64XOR&quot;: [ &quot;Succeeded&quot; ] }, &quot;type&quot;: &quot;Response&quot; } }, &quot;contentVersion&quot;: &quot;1.0.0.0&quot;, &quot;outputs&quot;: {}, &quot;parameters&quot;: {}, &quot;triggers&quot;: { &quot;manual&quot;: { &quot;inputs&quot;: { &quot;schema&quot;: { &quot;$id&quot;: &quot;http://example.com/example.json&quot;, &quot;$schema&quot;: &quot;http://json-schema.org/draft-07/schema&quot;, &quot;additionalProperties&quot;: true, &quot;default&quot;: {}, &quot;description&quot;: &quot;The root schema comprises the entire JSON document.&quot;, &quot;examples&quot;: [ { &quot;Content&quot;: &quot;你好我是Donma許&quot; } ], &quot;properties&quot;: { &quot;Content&quot;: { &quot;$id&quot;: &quot;#/properties/Content&quot;, &quot;default&quot;: &quot;&quot;, &quot;description&quot;: &quot;An explanation about the purpose of this instance.&quot;, &quot;examples&quot;: [ &quot;你好我是Donma許&quot; ], &quot;title&quot;: &quot;The Content schema&quot;, &quot;type&quot;: &quot;string&quot; } }, &quot;required&quot;: [ &quot;Content&quot; ], &quot;title&quot;: &quot;The root schema&quot;, &quot;type&quot;: &quot;object&quot; } }, &quot;kind&quot;: &quot;Http&quot;, &quot;type&quot;: &quot;Request&quot; } } }, &quot;parameters&quot;: {} }


如果你不看懂我在說啥,可以看 Azure Logic App - 使用 Inline Code 製作 Base64 Encode + XOR 加密 這一篇就知道我在說啥了,這邊就不贅述主要就是分享可以用的 sample code.

reference:

http://jsfiddle.net/gabrieleromanato/qAGHT/


當麻許的碎念筆記 2014 | Donma Hsu Design.