SHARE
TWEET

Untitled

a guest Jun 16th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function Decrypt(EncryptedPasswordBytes as byte()) as SecureString
  2.  
  3.     Dim Store As New X509Store(StoreName.TrustedPublisher,StoreLocation.LocalMachine)
  4.     Store.Open(OpenFlags.ReadOnly)
  5.  
  6.     Dim Cert = Store.Certificates.Find(X509FindType.FindByThumbprint,
  7.                                   "0ed0cfd7ffbeb3794013d03c8022f5ed7b45678", False)(0)
  8.     Dim PrivateKey = Cert.GetRSAPrivateKey
  9.  
  10.     Dim DecryptedPasswordBytes = PrivateKey.Decrypt(EncryptedPasswordBytes,
  11.                                    Security.Cryptography.RSAEncryptionPadding.OaepSHA256)
  12.  
  13.     Dim DecryptedPasswordChars = Encoding.UTF8.GetChars(DecryptedPasswordBytes)
  14.  
  15.     Array.Clear(DecryptedPasswordBytes, 0, DecryptedAppRolePasswordBytes.Length)
  16.  
  17.  
  18.     Dim SString As New SecureString
  19.  
  20.     For Each C In DecryptedAppRolePasswordChars
  21.            SString.AppendChar(C)
  22.     Next
  23.  
  24.     Array.Clear(DecryptedPasswordChars, 0, DecryptedPasswordChars.Length)
  25.  
  26.     SString.MakeReadOnly()
  27.  
  28.     Return SString
  29.  
  30. End Function
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top