-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-EncryptionKey.ps1
83 lines (77 loc) · 917 Bytes
/
New-EncryptionKey.ps1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<#
.SYNOPSIS
Generate a new random encryption key.
.DESCRIPTION
Generate a new random encryption key to be used with encrypting/decrypting
stored credential files.
.NOTES
Created by: Jason Wasser
Modified: 4/20/2017 11:34:25 AM
.PARAMETER KeyLength
Enter a valid key length for your encryption key.
.EXAMPLE
PS C:\> New-EncryptionKey
217
154
250
143
74
79
214
255
233
70
76
16
73
145
50
209
235
24
217
156
130
188
88
127
18
243
121
206
52
3
248
64
.EXAMPLE
PS C:\> New-EncryptionKey -KeyLength 16
206
152
255
54
205
81
218
131
0
100
122
160
141
126
82
110
#>
function New-EncryptionKey {
param (
[ValidateSet(16, 24, 32)]
[int]$KeyLength = 32
)
begin {}
process {
$EncryptKey = New-Object Byte[] $KeyLength #An example of 16 bytes key
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($EncryptKey)
$EncryptKey
}
end {}
}