469,282 Members | 1,704 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Generate Key using Cipher Block Chaining MAC

I want to encrypt the ASCII message using Cipher Block Chaining MAC and generate the 8 byte key.How can i achieve this?
Thanks:
Danish Majid
May 21 '07 #1
20 5695
Plater
7,872 Expert 4TB
http://en.wikipedia.org/wiki/CBC-MAC
May 21 '07 #2
RedSon
5,000 Expert 4TB
I want to encrypt the ASCII message using Cipher Block Chaining MAC and generate the 8 byte key.How can i achieve this?
Thanks:
Danish Majid
The document titled ISO/IEC 9797-2:2002 describes 3 algorithms you can use to create this. The document costs money but you can see if your local library or university library can get a copy for you.
May 21 '07 #3
Thanks for the reply but i implement CBC MAC using vb.net and generate 8 byte key through applying CBC MAC on the whole message. Do you know any website link/article where i can find source code for CBC MAC using vb.net because i can not find any code for CBC MAC in google.
Thanks:
Danish Majid
May 22 '07 #4
RedSon
5,000 Expert 4TB
Thanks for the reply but i implement CBC MAC using vb.net and generate 8 byte key through applying CBC MAC on the whole message. Do you know any website link/article where i can find source code for CBC MAC using vb.net because i can not find any code for CBC MAC in google.
Thanks:
Danish Majid
Microsoft already implements this method. http://msdn2.microsoft.com/en-us/library/aa382459.aspx
You can use their CryptoAPI.
May 22 '07 #5
The example described in this website used for encrypting data but i want to generate 8 byte key in output through applying CBC MAC to whole message.
suppose sample message is 642 ASCII characters
message=000542200000278945460202802026302002488987 12120......
the key generate by applying CBC MAC through this message is
key=24598762

this is my requirement to generate 8 byte key by applying CBC MAC to whole message.

How can i implement this in vb.net ? because i can only find code for encrypting message.
Thanks:
Danish
May 23 '07 #6
RedSon
5,000 Expert 4TB
The example described in this website used for encrypting data but i want to generate 8 byte key in output through applying CBC MAC to whole message.
suppose sample message is 642 ASCII characters
message=000542200000278945460202802026302002488987 12120......
the key generate by applying CBC MAC through this message is
key=24598762

this is my requirement to generate 8 byte key by applying CBC MAC to whole message.

How can i implement this in vb.net ? because i can only find code for encrypting message.
Thanks:
Danish
I don't know how to do it in VB but if C++ you would be looking for these functions: http://msdn2.microsoft.com/en-us/library/aa379908.aspx

Hopefully that will put you on the right path to finding the right libraries for VB
May 23 '07 #7
RedSon
5,000 Expert 4TB
I don't know how to do it in VB but if C++ you would be looking for these functions: http://msdn2.microsoft.com/en-us/library/aa379908.aspx

Hopefully that will put you on the right path to finding the right libraries for VB
Actually I found something that will help you better:
http://msdn2.microsoft.com/en-us/library/6yxzeb7e.aspx
May 23 '07 #8
Still i can not find solution to my problem on generating 8 byte hex key by applying CBC MAC to whole message using vb.net.
Any one can help me out?
May 24 '07 #9
Plater
7,872 Expert 4TB
I am still not sure what you are after, so I'll breakdown some parts

*You receive a message of 642ascii characters.
Is this the real message or an already encrypted message?

*You want to generate an 8byte DECRYPTION key for that message.
Now if the message was already encrypted, I don't think you can determine it's decrypting key just by looking at it, that kinda defeats the purpose don't you think? If the message is plain and you want the key that could be used to decrypt it once it's encrypted, then encrypt it and view the key that was used. Actually I think you can make up whatever key you want and use it to encrypt it.


But I always did bad at cryptology in school.
May 24 '07 #10
RedSon
5,000 Expert 4TB
I am still not sure what you are after, so I'll breakdown some parts

*You receive a message of 642ascii characters.
Is this the real message or an already encrypted message?

*You want to generate an 8byte DECRYPTION key for that message.
Now if the message was already encrypted, I don't think you can determine it's decrypting key just by looking at it, that kinda defeats the purpose don't you think? If the message is plain and you want the key that could be used to decrypt it once it's encrypted, then encrypt it and view the key that was used. Actually I think you can make up whatever key you want and use it to encrypt it.


But I always did bad at cryptology in school.
I took it to mean that the OP wants to create a signature key. A two way hash of the message to compare its authenticity. In any case, the links provided do show how to encrypt a message, decrypt a message, and create a hash of a message.
May 24 '07 #11
The 642 ASCII Characters are in Simple Plain Text and i want to generate 8 Byte key on applying CBC MAC to whole message. I dont know how to achieve this in vb.net?
May 25 '07 #12
RedSon
5,000 Expert 4TB
The 642 ASCII Characters are in Simple Plain Text and i want to generate 8 Byte key on applying CBC MAC to whole message. I dont know how to achieve this in vb.net?
What do you mean "create key"? You want to make the ASCII characters your key to use to encrypt data? Or do you want to create some kind of message digest or crytographic signature against the 642 ASCII Characters?

If you want to do the latter the link I provided in my prevoius post links directly to an article on MSDN as to how to Generate Signatures. It provides the VB code right there for you to look at. If you want to encrypt or decrypt data given a 642 ASCII Character key then right above where that page is on MSDN lists other Cryptograpic Tasks on how to Encrypt and Decrypt Data.

When you say "generate an 8 byte key" that means you want to create an 8 byte message digest (hash) or an 8 byte digital signature.
May 25 '07 #13
Hi,

I need to calculate the Cryptographic checksum using ISO/IEC 9797-1 MAC
algorithm with cipher block chaining MAC. The resultant MAC length must be 8 bytes.
As a sample, the data I am working on now is:
Data = '72C29C2371CC9BDB65B779B8E8D37B29ECC154AA56A8799FA E2F498F76ED92F2'
Kmac = '7962D9ECE03D1ACD4C76089DCE131543'


Resultant MAC[Kmac](Data)='53265320' (I want to know how to get
to this value using vb.net).
I search this on google but no success for the last 1 week.
Any code on urgent basis?
May 29 '07 #14
RedSon
5,000 Expert 4TB
Hi,

I need to calculate the Cryptographic checksum using ISO/IEC 9797-1 MAC
algorithm with cipher block chaining MAC. The resultant MAC length must be 8 bytes.
As a sample, the data I am working on now is:
Data = '72C29C2371CC9BDB65B779B8E8D37B29ECC154AA56A8799FA E2F498F76ED92F2'
Kmac = '7962D9ECE03D1ACD4C76089DCE131543'


Resultant MAC[Kmac](Data)='53265320' (I want to know how to get
to this value using vb.net).
I search this on google but no success for the last 1 week.
Any code on urgent basis?
This is the MSDN article about how to generate a cryptographic hash also known as a checksum.

http://msdn2.microsoft.com/en-us/lib...6k(vs.80).aspx

You will have to do some research to find out if Microsoft's implementation is equal to the ISO/IEC 9797-1 MAC algorithm. This will give you code samples on how to create something similar to what you need. Microsoft has implemented several cryptographic service providers for you to use. It is now up to you to read what is available on MSDN and try to use the crypto APIs to do what you need them to do or write your own custom crypto service provider.

Please be advised that it is never a good idea to create your own crypto service provider since there may be problems with the security of your algorithm. The CSPs provided by Microsoft have been throughly tested.
May 29 '07 #15
I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

Dim plainText As String
plainText = "HelloWorldhjslkajldalkdjlaksjdlakdja"
Dim DES As New System.Security.Cryptography.DESCryptoServiceProvi der
' Set the cipher mode.
DES.Mode = System.Security.Cryptography.CipherMode.CBC
' Create the encryptor.
Dim DESEncrypt As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor(Me.key, Me.iv)
' Get a byte array of the string.
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(plainText )
' Transform and return the string.
Dim keyout As String
keyout = Convert.ToBase64String(DESEncrypt.TransformFinalBl ock(Buffer, 0, Buffer.Length))
May 30 '07 #16
RedSon
5,000 Expert 4TB
I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

Dim plainText As String
plainText = "HelloWorldhjslkajldalkdjlaksjdlakdja"
Dim DES As New System.Security.Cryptography.DESCryptoServiceProvi der
' Set the cipher mode.
DES.Mode = System.Security.Cryptography.CipherMode.CBC
' Create the encryptor.
Dim DESEncrypt As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor(Me.key, Me.iv)
' Get a byte array of the string.
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(plainText )
' Transform and return the string.
Dim keyout As String
keyout = Convert.ToBase64String(DESEncrypt.TransformFinalBl ock(Buffer, 0, Buffer.Length))
I might be missing something but I do not see a call to ComputeHash().
May 30 '07 #17
ComputeHash function is available in MD5CryptoServiceProvider Class but in DESCryptoServiceProvider Class ComputeHash is not available instead it will provide ICryptoTransform function which uses CreateEncryptor method.

I studied that DES provide 8 byte output key but unable to generate the output key in 8 byte.waiting for any help?
May 31 '07 #18
pbmods
5,821 Expert 4TB
I have studied that DES CBC algorithm generate 64 bits (8 byte Hex) encrypted output but when i implement the algorithm in vb.net it gives the same length output as my plain text.i need help on how i obtain 8 byte encrypted output.

Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8}
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}

Dim plainText As String
plainText = "HelloWorldhjslkajldalkdjlaksjdlakdja"
Dim DES As New System.Security.Cryptography.DESCryptoServiceProvi der
' Set the cipher mode.
DES.Mode = System.Security.Cryptography.CipherMode.CBC
' Create the encryptor.
Dim DESEncrypt As System.Security.Cryptography.ICryptoTransform = DES.CreateEncryptor(Me.key, Me.iv)
' Get a byte array of the string.
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(plainText )
' Transform and return the string.
Dim keyout As String
keyout = Convert.ToBase64String(DESEncrypt.TransformFinalBl ock(Buffer, 0, Buffer.Length))
What does this output? Give us an example.
What were you expecting? Give us an example.
May 31 '07 #19
Banfa
9,064 Expert Mod 8TB
You might also consider telling us why you want to do this. You keep telling us what you want to do, the why often helps understand the problem too.
May 31 '07 #20
Basically i am developing a message interface document and send/receive data to server from my application using winsock TCP/IP. There is a MAC field in the document which apply CBC MAC encryption to plain text that i send to server and return 8 byte key in output.Then i send this 8 byte key with my plain text and the server check my message with their interface. At the server end their is a third party involved which developed server interface so they check my message and gives reply to me either transaction is OK/CANCEL.
When i am using TripleDES it generate 8 byte MAC Key but i want to generate CBC MAC key using DES.The code for TripleDES key is:
dim plaintext as string
plainText = "465465447987521234498798431321879841321465464 "
Dim data As Byte() = ASCIIEncoding.ASCII.GetBytes(plainText)
Dim mac3des As New MACTripleDES
Dim result As Byte() = mac3des.ComputeHash(data)
output=(result=52637299) 8 byte

Code for DES key is:
'Dim DES As New DESCryptoServiceProvider
'' Set the cipher mode.
'DES.Mode = CipherMode.CBC
'Dim data As Byte() = ASCIIEncoding.ASCII.GetBytes(plainText)
'If key Is Nothing Then
' DES.GenerateKey()
' DES.GenerateIV()
' key = DES.Key
' iv = DES.IV
'Else
' DES.Key = key
' DES.IV = iv
'End If

'Dim DESEncrypt As ICryptoTransform = DES.CreateEncryptor()
'Dim ms As New MemoryStream
'Dim cs As CryptoStream = New CryptoStream(ms, DESEncrypt, CryptoStreamMode.Write)
'cs.Write(data, 0, data.Length)
'cs.FlushFinalBlock()
'ms.Position = 0
'Dim result(ms.Length - 1) As Byte
'ms.Read(result, 0, ms.Length)
'cs.Close()
'Dim keyout As Byte()
'keyout = result
output=same length as plain text,i want keyout should be 8 byte.
I hope you understand this.
Jun 1 '07 #21

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by hopehope_123 | last post: by
5 posts views Thread by Michael Sperlle | last post: by
2 posts views Thread by Julio C. Hernandez Castro | last post: by
12 posts views Thread by iu2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.