Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using symmetric key (AES -128) to sign and verify a message

I want to know can symmetric keys be used to sign a message ? We can encrpyt using the shared secret key. Also when symmetric key is used for signing , what API can be used in JAVA to load the key and sign the message ?

if i used Signature from java.security , it has an api initSign but that takes private key from the public/private key pair as the argument to sign the message. Here the key is symmetric key.

Any pointers ?

like image 865
user839917 Avatar asked Nov 28 '11 17:11

user839917


2 Answers

A shared secret key can be used to calculate a Message Authentication Code (MAC), which then can be used to confirm the integrity and authenticity of the message to another party which knows the same shared secret. Unlike digital signatures, which are created using the private key and verified using the public key, MACs do not offer non-repudiation (anyone who can verify the MAC can also generate a MAC for another message).

There are different forms of message authentication codes; probably the most often used variation is HMAC.

like image 167
Sergey Vlasov Avatar answered Sep 23 '22 19:09

Sergey Vlasov


Symmetric algorithms can't give the non-repudiation property that asymmetric signature schemes give, i.e. the receiver of a message can't prove that he didn't create the message themselves, as they have to know the scheme.

That said, a message authentication code (MAC) can give you what you want: Both sender and receiver have a shared key, the sender calculates a MAC with the secret and appends it to the message, and the receiver calculates the same MAC and compares it with the received message.

While the most often used MAC type (HMAC) is based on hash functions, there are also ones which are based on a block cipher like AES, like CBC-MAC (this is like CBC, but with zero initialization vector and using only the last block as output). (As said by noloader, CBC-MAC is not the most secure way of doing this, use other modes.)

You should use message authentication in most cases where you use encryption, as many encryption schemes are vulnerable to chosen-plaintext attacks.

In Java, a MAC can be calculated (and checked) by using the javax.crypto.Mac class.

like image 43
Paŭlo Ebermann Avatar answered Sep 25 '22 19:09

Paŭlo Ebermann