Activity Stream
93,925 MEMBERS
50 ONLINE
Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES
Results 1 to 4 of 4
  1.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #1
    Special Member
    Senior Poster
    Mobile_Guru's Avatar
    Data Encryption-Decryption with AES

    Devil Data Encryption-Decryption with AES

    this AES protection is used on some of Nokia paid application this is a small tutorial which can help u to decrypt or atleast u can try yourself

    Let's begin


    For encryption we must use a secret key along with an algorithm. In the following example we use an algorithm called AES 128 and the bytes of the word "ThisIsASecretKey" as the secret key (the best secret key we found in this world). AES algorithm can use a key of 128 bits (16 bytes * 8); so we selected that key.

    Source Code : 
    package org.kamal.crypto;

    import java.security.*;
    import java.security.spec.InvalidKeySpecException;
    import javax.crypto.Cipher
    import javax.crypto.spec.SecretKeySpec;
    import sun.misc.*;

    public class 
    SimpleProtector {

        private static final 
    String ALGORITHM "AES";
        private static final 
    byte[] keyValue 
            new 
    byte[] { 'T''h''i''s''I''s''A''S''e''c''r''e''t''K''e''y' };

         public static 
    String encrypt(String valueToEncthrows Exception {
            
    Key key generateKey();
            
    Cipher c Cipher.getInstance(ALGORITHM);
            
    c.init(Cipher.ENCRYPT_MODEkey);
            
    byte[] encValue c.doFinal(valueToEnc.getBytes());
            
    String encryptedValue = new BASE64Encoder().encode(encValue);
            return 
    encryptedValue;
        }

        public static 
    String decrypt(String encryptedValuethrows Exception {
            
    Key key generateKey();
            
    Cipher c Cipher.getInstance(ALGORITHM);
            
    c.init(Cipher.DECRYPT_MODEkey);
            
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(encryptedValue);
            
    byte[] decValue c.doFinal(decordedValue);
            
    String decryptedValue = new String(decValue);
            return 
    decryptedValue;
        }

        private static 
    Key generateKey() throws Exception {
            
    Key key = new SecretKeySpec(keyValueALGORITHM);
            
    // SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
            // key = keyFactory.generateSecret(new DESKeySpec(keyValue));
            
    return key;
        }


    We use "generateKey()" method to generate a secret key for AES algorithm with a given key. You can change the used algorithm by changing this Key generation; the commented out code shows the use of DES algorithm (Data Encryption Standard). Following is a simple class to test the above implementation.

    Source Code : 
    package org.kamal.crypto;

    public class 
    TestSimpleProtector {

        public static 
    void main(String[] argsthrows Exception {

            
    String password "mypassword";
            
    String passwordEnc SimpleProtector.encrypt(password);
            
    String passwordDec SimpleProtector.decrypt(passwordEnc);

            
    System.out.println("Plain Text : " password);
            
    System.out.println("Encrypted : " passwordEnc);
            
    System.out.println("Decrypted : " passwordDec);
        }


    Following is the output we got from above test; so you clearly see that the original text is reproduced after the decryption operation.

    Source Code : 
    Plain Text mypassword
    Encrypted 
    sBhCap4urE50a/dGuhNgrw==
    Decrypted mypassword 
    The encrypted value is not simply related to the plain text, so it provides some security to the password.
    The Risk with Simple Protector

    When you use the above mentioned method to encrypt all passwords in your database, it makes an attacker's task easier. Since the same key is used, if an attacker find a way to get the plain text, the he can use that same method to get all the other plain-texts in the database in minutes.
    Use Salt and iterations to improve

    To make the attackers job harder we can use two methods; called adding Salt and using Iterations.
    A Salt is another plain-text appended to the given plain text, before generating the encrypted value. We use a unique Salt per each plain-text so that the value used to encrypt is getting much stronger making it harder for an attacker to guess with a brute force or dictionary attack. Following class shows the improved version of SimpleProtector class.

    Source Code : 
    package org.kamal.crypto;

    import java.security.*;
    import java.security.spec.InvalidKeySpecException;
    import javax.crypto.Cipher;
    import javax.crypto.spec.SecretKeySpec;
    import sun.misc.*;

    public class 
    Protector {

        private static final 
    String ALGORITHM "AES";
        private static final 
    int ITERATIONS 2;
        private static final 
    byte[] keyValue 
            new 
    byte[] { 'T''h''i''s''I''s''A''S''e''c''r''e''t''K''e''y'};

        public static 
    String encrypt(String valueString saltthrows Exception {
            
    Key key generateKey();
            
    Cipher c Cipher.getInstance(ALGORITHM);  
            
    c.init(Cipher.ENCRYPT_MODEkey);
      
            
    String valueToEnc null;
            
    String eValue value;
            for (
    int i 0ITERATIONSi++) {
                
    valueToEnc salt eValue;
                
    byte[] encValue c.doFinal(valueToEnc.getBytes());
                
    eValue = new BASE64Encoder().encode(encValue);
            }
            return 
    eValue;
        }

        public static 
    String decrypt(String valueString saltthrows Exception {
            
    Key key generateKey();
            
    Cipher c Cipher.getInstance(ALGORITHM);
            
    c.init(Cipher.DECRYPT_MODEkey);
      
            
    String dValue null;
            
    String valueToDecrypt value;
            for (
    int i 0ITERATIONSi++) {
                
    byte[] decordedValue = new BASE64Decoder().decodeBuffer(valueToDecrypt);
                
    byte[] decValue c.doFinal(decordedValue);

    [Login or Register to remove this advertisement]

                
    dValue = new String(decValue).substring(salt.length());
                
    valueToDecrypt dValue;
            }
            return 
    dValue;
        }

        private static 
    Key generateKey() throws Exception {
            
    Key key = new SecretKeySpec(keyValueALGORITHM);
            
    // SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
            // key = keyFactory.generateSecret(new DESKeySpec(keyValue));
            
    return key;
        }


    You need to store the clear Salt with the stored encrypted value since the salt is required at the decrypt operation. We just used a sentence as the 'salt', but you should use a random letters/numbers for that to avoid any dictionary attacks.

    Source Code : 
    package org.kamal.crypto;

    public class 
    TestProtector {

        public static 
    void main(String[] argsthrows Exception {
            
    String password "mypassword";
            
    String salt "this is a simple clear salt";
            
    String passwordEnc Protector.encrypt(passwordsalt);
            
    String passwordDec Protector.decrypt(passwordEncsalt);

            
    System.out.println("Salt Text : " salt);
            
    System.out.println("Plain Text : " password);
            
    System.out.println("Encrypted : " passwordEnc);
            
    System.out.println("Decrypted : " passwordDec);
        }


    The output from the above class looks as follows.

    Source Code : 
    Salt Text this is a simple clear salt
    Plain Text 
    mypassword
    Encrypted 
    GX8jEr04o6PC+IE+f6DXq+zuRiZ2nsSL+UYxYRh9vK28xt/GrLqnbrP3hkXSW5S3jNgzXkrLSmXm
    fwRw
    +eBMWQJO+8tlSEE9D2Y9qEzowX18s4W81U/D9JL3JX7uJtwp
    Decrypted 
    mypassword 
    ALL AES 128 Encryption-Decryption cipher keys
    [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]


    implementing using c++ program download above guide
    [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]


    If u know more information than i provided please feel free to share with us
    THIS IS ONLY FOR EDUCATIONAL PURPOSE ONLY
    Mobile_Guru Reviewed by Mobile_Guru on . Data Encryption-Decryption with AES this AES protection is used on some of Nokia paid application this is a small tutorial which can help u to decrypt or atleast u can try yourself :cu: Let's begin :by: For encryption we must use a secret key along with an algorithm. In the following example we use an algorithm called AES 128 and the bytes of the word "ThisIsASecretKey" as the secret key (the best secret key we found in this world). AES algorithm can use a key of 128 bits (16 bytes * 8); so we selected that key. Rating: 5

  2.   Advertisements

  3.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #2
    Special Member
    Senior Poster
    Mobile_Guru's Avatar
    Data Encryption-Decryption with AES

    mwpda usage information

    Encryption methods

    For request generator binding settings, the encryption methods include specifying the data and key encryption algorithms to use to encrypt the SOAP message. The WSS API for encryption (WSSEncryption) specifies the algorithm name and the matching algorithm uniform resource identifier (URI) for the data and key encryption methods. If the data and key encryption algorithms are specified, only elements that are encrypted with those algorithms are accepted.
    Data encryption algorithms

    The data encryption algorithm is used to encrypt parts of the SOAP message, including the body and the signature. Data encryption algorithms specify the algorithm uniform resource identifier (URI) for each type of data encryption algorithms.
    The following pre-configured data encryption algorithms are supported:
    Data encryption algorithm name Algorithm URI
    WSSEncryption.AES128 (the default value) A URI of data encryption algorithm, AES 128: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    (NOKIA APPLICATIONS PROTECTED METHOD)
    WSSEncryption.AES192 A URI of data encryption algorithm, AES 192: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.AES256 A URI of data encryption algorithm, AES 256: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.TRIPLE_DES A URI of data encryption algorithm, TRIPLE DES: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]


    By default, the Java Cryptography Extension (JCE) is shipped with restricted or limited strength ciphers. To use 192-bit and 256-bit Advanced Encryption Standard (AES) encryption algorithms, you must apply unlimited jurisdiction policy files.
    Important: Your country of origin might have restrictions on the import, possession, use, or re-export to another country, of encryption software. Before downloading or using the unrestricted policy files, you must check the laws of your country, its regulations, and its policies concerning the import, possession, use, and re-export of encryption software, to determine if it is permitted.
    For the AES256-cbc and the AES192-CBC algorithms, you must download the unrestricted Java™ Cryptography Extension (JCE) policy files from the following website: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    .
    The data encryption algorithm configured for encryption for the generator side must match the data encryption algorithm that is configured for decryption for the consumer side.

    Key encryption algorithms

    This algorithm is used to encrypt and decrypt keys. This key information is used to specify the configuration that is needed to generate the key for digital signature and encryption. The signing information and encryption information configurations can share the key information. The key information on the consumer side is used for specifying the information about the key that is used for validating the digital signature in the received message or for decrypting the encrypted parts of the message. The request generator is configured for the client.
    Note: Policy sets do not support symmetric key encryption. If you are using the WSS API for symmetric key encryption, you will not be able to interoperate with web services endpoints using the policy sets.
    Key encryption algorithms specify the algorithm uniform resource identifier (URI) of the key encryption method. The following pre-configured key encryption algorithms are supported:
    WSS API URI
    WSSEncryption.KW_AES128 A URI of key encryption algorithm, key wrap AES 128: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.KW_AES192 A URI of key encryption algorithm, key wrap AES 192: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    Restriction: Do not use the 192-bit key encryption algorithm if you want your configured application to be in compliance with the Basic Security Profile (BSP).
    WSSEncryption.KW_AES256 A URI of key encryption algorithm, key wrap AES 256: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.KW_RSA_OAEP (the default value) A URI of key encryption algorithm, key wrap RSA OAEP: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.KW_RSA15 A URI of key encryption algorithm, key wrap RSA 1.5: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    WSSEncryption.KW_TRIPLE_DES A URI of key encryption algorithm, key wrap TRIPLE DES: [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]

    For Secure Conversation, additional key-related information must be specified, such as:
    • algorithmName
    • keyLength


    By default, the RSA-OAEP algorithm uses the SHA1 message digest algorithm to compute a message digest as part of the encryption operation. Optionally, you can use the SHA256 or SHA512 message digest algorithm by specifying a key encryption algorithm property. The property name is:com.ibm.wsspi.wssecurity.enc.rsaoaep.DigestMethod. The property value is one of the following URIs of the digest method:


    By default, the RSA-OAEP algorithm uses a null string for the optional encoding octet string for the OAEPParams. You can provide an explicit encoding octet string by specifying a key encryption algorithm property. For the property name, you can specifycom.ibm.wsspi.wssecurity.enc.rsaoaep.OAEPparams. The property value is the base 64-encoded value of the octet string.
    Important: You can set these digest method and OAEPParams properties on the generator side only. On the consumer side, these properties are read from the incoming SOAP message.
    For the KW-AES256 and the KW-AES192 key encryption algorithms, you must download the unrestricted JCE policy files from the following website:[Only Registered and Activated users can see Content.
    Click Here To Register..
    ]
    .
    The key encryption algorithm for the generator must match the key decryption algorithm that is configured for the consumer.

    This example provides sample code for encryption to use the Triple DES for the data encryption method and to use RSA1.5 for the key encryption method:


    Source Code : 
     // get the message context
          
    Object msgcontext getMessageContext();

          
    // generate WSSFactory instance
          
    WSSFactory factory WSSFactory.getInstance();        

          
    // generate WSSGenerationContext instance
          
    WSSGenerationContext gencont factory.newWSSGenerationContext();

          
    // generate callback handler
          
    X509GenerateCallbackHandler callbackHandler = new X509GenerateCallbackHandler(
                  
    "",
                  
    "enc-sender.jceks",
                  
    "jceks"
                  
    "storepass".toCharArray(), 
                  
    "bob"
                  
    null
                  
    "CN=Bob, O=IBM, C=US"
                  
    null);

          
    // generate the security token used to the encryption
          
    SecurityToken token factory.newSecurityToken(X509Token.class, 
            
    callbackHandler);

          
    // generate WSSEncryption instance to encrypt the SOAP body content
          
    WSSEncryption enc factory.newWSSEncryption(token);
          
    enc.addEncryptPart(WSSEncryption.BODY_CONTENT);

          
    // set the data encryption method
          // DEFAULT: WSSEncryption.AES128
          
    enc.setEncryptionMethod(WSSEncryption.TRIPLE_DES);

          
    // set the key encryption method
          // DEFAULT: WSSEncryption.KW_RSA_OAEP
          
    enc.setEncryptionMethod(WSSEncryption.KW_RSA15);

          
    // add the WSSEncryption to the WSSGenerationContext
          
    gencont.add(enc);

          
    // generate the WS-Security header
          
    gencont.process(msgcontext); 

  4. The Following 2 Users Say Thank You to Mobile_Guru For This Useful Post:
    [ Click to Expand ]

    pintudada (28th October 2012),ziutek51 (6th January 2013)

  5.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #3
    thanks for your helpful code. could you please post the code for password protected key.my requirement is like i need to decrypt a file by using key and password using rsa algorithm. [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]

    thanks in advance....
    [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]

  6.    Tweet this post   Share This Post On Facebook Share This Post On Google+
    #4
    I agree with thanks for your helpful code.




    ______
    [Only Registered and Activated users can see Content.
    Click Here To Register..
    ]

Thread Information

Users Browsing this Thread

There Are Currently 1 Users Browsing This Thread. (0 Members and 1 Guests)

Similar Threads

  1. Encryption SMS
    By Amar in forum S40 Applications
    Replies: 0
    Last Post: 9th January 2012, 10:22 PM
  2. RSA String Encryption
    By Amar in forum Android Tips & Tutorial
    Replies: 0
    Last Post: 22nd December 2011, 06:04 PM
  3. Replies: 1
    Last Post: 22nd October 2011, 09:17 PM
  4. File Encryption v1.0 EN by POPDA
    By Rebel in forum Python S60 Zone
    Replies: 5
    Last Post: 25th June 2011, 04:39 PM
  5. New Flash Drives Have Antivirus and Data Encryption
    By [email protected]$h in forum Tech News
    Replies: 0
    Last Post: 6th April 2011, 03:45 PM

Tags for this Thread

BE SOCIAL
Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES Data Encryption-Decryption with AES