-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase64.cs
58 lines (46 loc) · 1.93 KB
/
Base64.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Management.Automation;
using System;
namespace Base64
{
[Cmdlet(VerbsData.ConvertTo, "Base64String")]
[OutputType(typeof(string))]
public class ConvertToBase64Command : Cmdlet
{
// Declare the parameters for the cmdlet.
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
[Alias("InputString","String","Text")]
public string InputObject { get; set; }
[Parameter]
[ArgumentCompleter(typeof(EncodingCompleter))]
[EncodingTransform]
public System.Text.Encoding Encoding { get; set; } = EncodingTransformAttribute.StandardEncoding["UTF8"];
//This is the "Process {}" block of a Powershell script
protected override void ProcessRecord()
{
//WriteObject("Hello " + name + "!");
byte[] bytes = Encoding.GetBytes(InputObject);
WriteObject(Convert.ToBase64String(bytes), true);
}
} //class
[Cmdlet(VerbsData.ConvertFrom, "Base64String")]
[OutputType(typeof(string))]
public class ConvertFromBase64Command : Cmdlet
{
// Declare the parameters for the cmdlet.
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
[Alias("InputString","String","Text")]
public string InputObject { get; set; }
[Parameter]
[ArgumentCompleter(typeof(EncodingCompleter))]
[EncodingTransform]
public System.Text.Encoding Encoding { get; set; } = EncodingTransformAttribute.StandardEncoding["UTF8"];
//This is the "Process {}" block of a Powershell script
protected override void ProcessRecord()
{
//WriteObject("Hello " + name + "!");
// $Encoding.GetString([System.Convert]::FromBase64String($Base64String))
byte[] bytes = Convert.FromBase64String(InputObject);
WriteObject(Encoding.GetString(bytes), true);
}
} //class
} //namespace