CopyPastor

Detecting plagiarism made easy.

Score: 0.8239101527224169; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2013-05-02
by onkar

Original Post

Original - Posted on 2013-05-02
by onkar



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Use this code to encrypt your string

import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import android.util.Base64; //string encryption public class EncryptionHelper { // Encrypts string and encode in Base64 public static String encryptText(String plainText) throws Exception { // ---- Use specified 3DES key and IV from other source -------------- byte[] plaintext = plainText.getBytes();//input byte[] tdesKeyData = Constants.getKey().getBytes();// your encryption key byte[] myIV = Constants.getInitializationVector().getBytes();// initialization vector Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding"); SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede"); IvParameterSpec ivspec = new IvParameterSpec(myIV); c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec); byte[] cipherText = c3des.doFinal(plaintext); String encryptedString = Base64.encodeToString(cipherText, Base64.DEFAULT); // return Base64Coder.encodeString(new String(cipherText)); return encryptedString; } }
This is how you can encrypt the string
String encryptedPassword = EncryptionHelper.encryptText(edtText.getText().toString());
**EDIT** Code for `Constants.java`
Class Constants { private final String initializationVector = "INITALIZATION_VECTOR"; private final String ecnryptionKey = "ENCRYPTION_KEY"; public static String getInitializationVector() { return initializationVector; } public static String getKey() { return ecnryptionKey; } }
Use this code to encrypt your string

import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import android.util.Base64; //string encryption public class EncryptionHelper { // Encrypts string and encode in Base64 public static String encryptText(String plainText) throws Exception { // ---- Use specified 3DES key and IV from other source -------------- byte[] plaintext = plainText.getBytes();//input byte[] tdesKeyData = Constants.getKey().getBytes();// your encryption key byte[] myIV = Constants.getInitializationVector().getBytes();// initialization vector Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding"); SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede"); IvParameterSpec ivspec = new IvParameterSpec(myIV); c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec); byte[] cipherText = c3des.doFinal(plaintext); String encryptedString = Base64.encodeToString(cipherText, Base64.DEFAULT); // return Base64Coder.encodeString(new String(cipherText)); return encryptedString; } private class Constants { private static final String KEY="QsdPasd45FaSdnLjf"; private static final String INITIALIZATION_VECTOR="l9yhTaWY"; public static String getKey() { return KEY; } public static String getInitializationVector() { return INITIALIZATION_VECTOR; } } }
This is how you can encrypt the string
String encryptedPassword = EncryptionHelper.encryptText(edtText.getText().toString());

        
Present in both answers; Present only in the new answer; Present only in the old answer;