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 ?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With