Private/Get-SNMPv3PrivacyProvider.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
function Get-SNMPv3PrivacyProvider
{
    param(
        [string]$PrivType,
        [Lextm.SharpSnmpLib.OctetString]$PrivSecret,
        [Lextm.SharpSnmpLib.Security.IAuthenticationProvider]$Auth
    )
    
    switch ($PrivType)
    {
        'DES'
        { 
            if ([Lextm.SharpSnmpLib.Security.DESPrivacyProvider]::IsSupported) {
                [Lextm.SharpSnmpLib.Security.DESPrivacyProvider]::new($PrivSecret, $Auth)
            } else {
                [SNMPv3.BouncyCastle.BouncyCastleDESPrivacyProvider]::new($PrivSecret, $Auth)
            }
        }

        'TribleDES'
        {
            [Lextm.SharpSnmpLib.Security.TripleDESPrivacyProvider]::new($PrivSecret, $Auth)
        }
        
        'AES128'
        {
            if ([Lextm.SharpSnmpLib.Security.AESPrivacyProviderBase]::IsSupported) {
                [Lextm.SharpSnmpLib.Security.AESPrivacyProvider]::new($PrivSecret, $Auth)
            } else {
                [SNMPv3.BouncyCastle.BouncyCastleAESPrivacyProvider]::new($PrivSecret, $Auth)
            }
        }

        'AES192'
        {
            if ([Lextm.SharpSnmpLib.Security.AESPrivacyProviderBase]::IsSupported) {
                [Lextm.SharpSnmpLib.Security.AES192PrivacyProvider]::new($PrivSecret, $Auth)
            } else {
                [SNMPv3.BouncyCastle.BouncyCastleAES192PrivacyProvider]::new($PrivSecret, $Auth)
            }
        }

        'AES256'
        {
            if ([Lextm.SharpSnmpLib.Security.AESPrivacyProviderBase]::IsSupported) {
                [Lextm.SharpSnmpLib.Security.AES256PrivacyProvider]::new($PrivSecret, $Auth)
            } else {
                [SNMPv3.BouncyCastle.BouncyCastleAES256PrivacyProvider]::new($PrivSecret, $Auth)
            }
        }

        default
        {
            [Lextm.SharpSnmpLib.Security.DefaultPrivacyProvider]::new($Auth)
        }
    }
}