Encrypting using "Cryptography.HMACSHA1", how to decrypt (VBA) I have an encryption routine that works very well in VBA. But now I need to program the decryption routine, and I'm stuck. For encryption I'm using HMACSHA1 and transferring the encrypted byte to base 64. I can decode the base 64 and get the same byte array back, but any suggestion on how to use the HMACSHA1 to decrypt? Here's what I have so far (sorry if this is not the right place to ask these kinds of questions):

Private Function fDecrypto(sText As String, sPass As String) As String

Dim encoder As Object
Dim crypto As Object
Dim bEncrypted() As Byte
Dim i As Integer

' base64 to encrypted byte array

Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")

objNode.DataType = "bin.base64"
objNode.Text = sText
bEncrypted = objNode.nodeTypedValue

Set objNode = Nothing
Set objXML = Nothing

' decrypt using HMACSHA1

Set encoder = CreateObject("System.Text.UTF8Encoding")
Set crypto = CreateObject("System.Security.Cryptography.HMACSHA1")

' **TODO - decrypt here**

Set encoder = Nothing
Set crypto = Nothing

End Function


Private Function fEncrypto(sText As String, sPass As String) As String

Dim encoder  As Object
Dim crypto As Object
Dim i As Integer
Dim bPass() As Byte
Dim bText() As Byte
Dim bEncrypted() As Byte

Set encoder = CreateObject("System.Text.UTF8Encoding")
Set crypto = CreateObject("System.Security.Cryptography.HMACSHA1")

bText = encoder.Getbytes_4(sText)
bPass = encoder.Getbytes_4(sPass)
crypto.key = bPass

bEncrypted = crypto.ComputeHash_2(bText)

Set encoder = Nothing
Set crypto = Nothing

' encrypted byte array to base64

Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")

objNode.DataType = "bin.base64"
objNode.nodeTypedValue = bEncrypted
EncodeBase64 = objNode.Text

Set objNode = Nothing
Set objXML = Nothing

End Function
HMAC is a message authentication code (MAC). MACs produce "tags" that can can be used to prevent a message from being tampered with (sort of like a digital signature). There's no way to "decrypt" an HMAC tag to get back the original message, so it sounds like HMAC is not what you're looking for.

I would suggest using AES-GCM instead, since it's designed to be used for encryption. I'm not sure how to use AES-GCM from VBA: I suggest asking that on StackOverflow (that question would be off-topic here).