Commit 994d9be5 authored by Lily Tsai's avatar Lily Tsai
Browse files

change to cbc

parent bc610edd
Subproject commit eb462f82708dc82b5c57333b5d5d608a9bc15bc5
Subproject commit c5cdbe909381455f0dfec7ff287e96bf59b49a24
......@@ -95,7 +95,7 @@ public abstract class ContentProviderBase extends ContentProvider {
final Uri insertedRowURI = ContentUris.withAppendedId(EncounterHistoryAPM.getContentURI(dmb), rowID);
getContext().getContentResolver().notifyChange(insertedRowURI, null);
return insertedRowURI;
} catch (Exception e) {
} catch (SQLException e) {
Log.e(TAG, e.getMessage());
}
return null;
......
package org.mpisws.embeddedsocial;
import com.microsoft.embeddedsocial.autorest.EmbeddedSocialClientImpl;
import com.microsoft.embeddedsocial.autorest.models.PostTopicRequest;
import com.microsoft.embeddedsocial.autorest.models.TopicView;
import org.apache.commons.lang3.tuple.ImmutablePair;
......@@ -31,12 +33,19 @@ import static org.mpisws.helpers.Utils.hexStringToByteArray;
public class TestBatchClient {
static final String auth = "SocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNjZHFzN0paYVxuR29vZ2xlXG4xMTAyMDM3NjQyMDI5ODI4NDk3NTYiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ3Mzg1NTA0fQ.DhURO4E5-BEFz_dWMdHZHQLq-E_fZf62_si-UlqF3Ko";
static final String topicHandle = "3gcpdys3KfY";
static final String topicHandle = "3g_nGuswN8z";
static final String ss = "0E31177095EE530101D89573C8261C14F51A3877D4676F74478F5CAF";
public static void main(String[] args) {
ESClient.getInstance().setESCredentials("user", auth);
ESClient.getInstance().setESAPIKey("2e5a1cc8-5eab-4dbd-8d6d-6a84eab23374");
/*new Thread( () -> {
String topicHandle = ESClient.getInstance().createOneTopic(
new ImmutablePair<>(
new Identifier("hello".getBytes()),
new Identifier("hello".getBytes())));
System.out.println(topicHandle);
}).start();*/
new Thread( () -> {
System.out.println("Starting!");
......
......@@ -6,6 +6,7 @@ import java.util.Arrays;
import java.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
......@@ -36,14 +37,14 @@ public class Coder {
try
{
SecretKeySpec secretKey;
MessageDigest sha = null;
MessageDigest sha;
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
secretKey = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(new byte[16]));
String result = Base64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));
System.out.println("CODER: Encrypting message \n"
+ strToEncrypt
......@@ -64,16 +65,16 @@ public class Coder {
return strToDecrypt;
try
{
System.out.println("CODER: Decrypting message " + strToDecrypt + " \nwith secret " + new Identifier(secret).toString());
SecretKeySpec secretKey;
MessageDigest sha = null;
MessageDigest sha;
sha = MessageDigest.getInstance("SHA-1");
secret = sha.digest(secret);
secret = Arrays.copyOf(secret, 16);
System.out.println("CODER: Decrypting message " + strToDecrypt + " \nwith secret " + new Identifier(secret).toString());
secretKey = new SecretKeySpec(secret, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(new byte[16]));
return new String(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));
}
catch (Exception e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment