|
SMSLib_Encryption
SMSLib Encrypted Messages
SMSLib - Message encryptionIntroductionStarting from v3.4.1, SMSLib offers you the functionality to send and receive encrypted messages. Enrypted messages can either be text or binary messages. In all cases, SMSLib converts these messages to binary messages in order to be safely transmitted over GSM. If both parties are using SMSLib (i.e. both the originator and the recipient), SMSLib provides all the necessary functionality to automatically encrypt/decrypt the messages without much of user intervention. Even if one party is using SMSLib, you can easily decrypt messages yourselves at the other end, once you get the idea of how this is done. EncryptionSMSLib currently uses the AES strong key (128bit) encryption algorithm, which is available in JDK 5. It's strong enough and spares the core library from external dependencies. Other algorithms or stronger cipher implementation (like BouncyCastle) are easy to be implemented as well. The current SMSLib implementation is for symmetric encryption algorithms - the next step will be to implement an asymmetric algorithm as well in order to have it as reference. The new org.smslib.crypto packageThe org.smslib.crypto contains the following classes:
New message classesSMSLib has two new classes implemented: The InboundEncryptedMessage and the OutboundEncryptedMessage. These classes encapsulate the details of the encrypted messages. How everything wraps upHere are the details for the implementation of message encryption. Setup the KeyManagerBefore attempting to send or receive messages, you need to setup the details in the Key Manager. The Key Manager holds encryption keys per source or destination. So, assuming that you need to send an encrypted message to a certain number, you should declare this as follows: srv.getKeyManager().registerKey("+306948494037", new AESKey(new SecretKeySpec("0011223344556677".getBytes(), "AES")));This command makes SMSLib remember that when sending an encrypted message to "+306948494037", it should use the AES algorithm with the key "0011223344556677". You should similarly declare all originator / recipient numbers and their keys. Sending an encrypted messageOnce the key is set, you are ready to send the message. Remember to use the new OutboundEncryptedMessage class! OutboundEncryptedMessage msg = new OutboundEncryptedMessage("+306948494037", "Hello (encrypted) from SMSLib!".getBytes());That's all! For an actual implementation, look at the examples.modem.SendEncryptedMessage sample application. Receiving encrypted messagesOnce again, before reception of messages you should set up the Key Manager in order for SMSLib to know and decrypt received messages correctly. The reception of messages works like before. In the case where a message is received from a recipient which is declared in the Key Manager, SMSLib will push a message of InboundEncryptedMessage class. Use the getDecryptedText() method to get the "clear" message text. Frequently asked questionsI want to implement another symmetric algorithm. Extend the ASymmetricKey class with the necessary code. Have a look at the AESKey for reference. What if you forget the Key Manager definitions? Outbound messages will throw exceptions upon creation of the OutboundEncryptedMessage object. Inbound messages will be received as binaries with "ciphered", unreadable text. What if the key in Key Manager is wrong? Outbound messages will be sent, however the wrong key will prevent the recipient from decoding your data. Inbound messages will throw exceptions upon receipt, as the crypto algorithm will fail to decrypt the content. |
Sign in to add a comment