2번과 관련된 문서는 따로 없습니다.
그리고 전달해주신 코드를 참고삼아 해봤을때는 잘 동작하고있고, Iam님이 전달해주신 설정값과 비교해봤을때 다른 부분은 아래와 같습니다.
- build.gradle(project)의 gradle version : classpath “com.android.tools.build:gradle:4.1.2”
- build.gradle(:app)에서의 buildToolsVersion : buildToolsVersion “30.0.3”
위 설정값을 바꿔보시고 한번 실행 부탁드립니다.
저의 gradle 설정 파일과 Test 코드 공유드립니다.(JUNIT으로 Test를 진행했습니다.)
<build.gradle(project)>
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
<build.grade(:app)>
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.klaytn.caver:core:1.5.7-android'
implementation 'com.google.code.gson:gson:2.8.6'
implementation ("com.squareup.okhttp3:okhttp:3.12.12"){
force = true
}
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.12'
}
Test code
package com.example.myapplication;
import com.klaytn.caver.wallet.keyring.AbstractKeyring;
import com.klaytn.caver.wallet.keyring.KeyringFactory;
import com.klaytn.caver.wallet.keyring.MultipleKeyring;
import com.klaytn.caver.wallet.keyring.PrivateKey;
import com.klaytn.caver.wallet.keyring.RoleBasedKeyring;
import com.klaytn.caver.wallet.keyring.SingleKeyring;
import org.junit.Test;
import org.web3j.crypto.CipherException;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
String jsonV4 ="{\n" +
" \"version\":4,\n" +
" \"id\":\"55da3f9c-6444-4fc1-abfa-f2eabfc57501\",\n" +
" \"address\":\"0x86bce8c859f5f304aa30adb89f2f7b6ee5a0d6e2\",\n" +
" \"keyring\":[\n" +
" [\n" +
" {\n" +
" \"ciphertext\":\"93dd2c777abd9b80a0be8e1eb9739cbf27c127621a5d3f81e7779e47d3bb22f6\",\n" +
" \"cipherparams\":{\"iv\":\"84f90907f3f54f53d19cbd6ae1496b86\"},\n" +
" \"cipher\":\"aes-128-ctr\",\n" +
" \"kdf\":\"scrypt\",\n" +
" \"kdfparams\":{\n" +
" \"dklen\":32,\n" +
" \"salt\":\"69bf176a136c67a39d131912fb1e0ada4be0ed9f882448e1557b5c4233006e10\",\n" +
" \"n\":4096,\n" +
" \"r\":8,\n" +
" \"p\":1\n" +
" },\n" +
" \"mac\":\"8f6d1d234f4a87162cf3de0c7fb1d4a8421cd8f5a97b86b1a8e576ffc1eb52d2\"\n" +
" },\n" +
" {\n" +
" \"ciphertext\":\"53d50b4e86b550b26919d9b8cea762cd3c637dfe4f2a0f18995d3401ead839a6\",\n" +
" \"cipherparams\":{\"iv\":\"d7a6f63558996a9f99e7daabd289aa2c\"},\n" +
" \"cipher\":\"aes-128-ctr\",\n" +
" \"kdf\":\"scrypt\",\n" +
" \"kdfparams\":{\n" +
" \"dklen\":32,\n" +
" \"salt\":\"966116898d90c3e53ea09e4850a71e16df9533c1f9e1b2e1a9edec781e1ad44f\",\n" +
" \"n\":4096,\n" +
" \"r\":8,\n" +
" \"p\":1\n" +
" },\n" +
" \"mac\":\"bca7125e17565c672a110ace9a25755847d42b81aa7df4bb8f5ce01ef7213295\"\n" +
" }\n" +
" ],\n" +
" [\n" +
" {\n" +
" \"ciphertext\":\"f16def98a70bb2dae053f791882f3254c66d63416633b8d91c2848893e7876ce\",\n" +
" \"cipherparams\":{\"iv\":\"f5006128a4c53bc02cada64d095c15cf\"},\n" +
" \"cipher\":\"aes-128-ctr\",\n" +
" \"kdf\":\"scrypt\",\n" +
" \"kdfparams\":{\n" +
" \"dklen\":32,\n" +
" \"salt\":\"0d8a2f71f79c4880e43ff0795f6841a24cb18838b3ca8ecaeb0cda72da9a72ce\",\n" +
" \"n\":4096,\n" +
" \"r\":8,\n" +
" \"p\":1\n" +
" },\n" +
" \"mac\":\"38b79276c3805b9d2ff5fbabf1b9d4ead295151b95401c1e54aed782502fc90a\"\n" +
" }\n" +
" ],\n" +
" [\n" +
" {\n" +
" \"ciphertext\":\"544dbcc327942a6a52ad6a7d537e4459506afc700a6da4e8edebd62fb3dd55ee\",\n" +
" \"cipherparams\":{\"iv\":\"05dd5d25ad6426e026818b6fa9b25818\"},\n" +
" \"cipher\":\"aes-128-ctr\",\n" +
" \"kdf\":\"scrypt\",\n" +
" \"kdfparams\":{\n" +
" \"dklen\":32,\n" +
" \"salt\":\"3a9003c1527f65c772c54c6056a38b0048c2e2d58dc0e584a1d867f2039a25aa\",\n" +
" \"n\":4096,\n" +
" \"r\":8,\n" +
" \"p\":1\n" +
" },\n" +
" \"mac\":\"19a698b51409cc9ac22d63d329b1201af3c89a04a1faea3111eec4ca97f2e00f\"\n" +
" },\n" +
" {\n" +
" \"ciphertext\":\"dd6b920f02cbcf5998ed205f8867ddbd9b6b088add8dfe1774a9fda29ff3920b\",\n" +
" \"cipherparams\":{\"iv\":\"ac04c0f4559dad80dc86c975d1ef7067\"},\n" +
" \"cipher\":\"aes-128-ctr\",\n" +
" \"kdf\":\"scrypt\",\n" +
" \"kdfparams\":{\n" +
" \"dklen\":32,\n" +
" \"salt\":\"22279c6dbcc706d7daa120022a236cfe149496dca8232b0f8159d1df999569d6\",\n" +
" \"n\":4096,\n" +
" \"r\":8,\n" +
" \"p\":1\n" +
" },\n" +
" \"mac\":\"1c54f7378fa279a49a2f790a0adb683defad8535a21bdf2f3dadc48a7bddf517\"\n" +
" }\n" +
" ]\n" +
" ]\n" +
"}";
public static void checkValidKeyring(AbstractKeyring expect, AbstractKeyring actual) {
assertEquals(expect.getAddress(), actual.getAddress());
assertEquals(expect.getClass(), actual.getClass());
if(expect instanceof SingleKeyring) {
assertEquals(((SingleKeyring) expect).getKey().getPrivateKey(), ((SingleKeyring)actual).getKey().getPrivateKey());
}
if(expect instanceof MultipleKeyring) {
MultipleKeyring expectKeyring = (MultipleKeyring)expect;
MultipleKeyring actualKeyring = (MultipleKeyring)actual;
for(int i=0; i<expectKeyring.getKeys().length; i++) {
assertEquals(expectKeyring.getKeys().length, actualKeyring.getKeys().length);
}
}
if(expect instanceof RoleBasedKeyring) {
RoleBasedKeyring expectKeyring = (RoleBasedKeyring)expect;
RoleBasedKeyring actualKeyring = (RoleBasedKeyring)actual;
for(int i=0; i< expectKeyring.getKeys().size(); i++) {
PrivateKey[] actualArr = actualKeyring.getKeys().get(i);
PrivateKey[] expectedArr = expectKeyring.getKeys().get(i);
assertEquals(expectedArr.length, actualArr.length);
for(int j=0; j<actualArr.length; j++) {
assertEquals(expectedArr[j].getPrivateKey(), actualArr[j].getPrivateKey());
}
}
}
}
@Test
public void decrypt() throws CipherException, IOException {
String password = "password";
String expectedAddress = "0x86bce8c859f5f304aa30adb89f2f7b6ee5a0d6e2";
String[][] expectedPrivateKeys = new String[][] {
{
"0xd1e9f8f00ef9f93365f5eabccccb3f3c5783001b61a40f0f74270e50158c163d",
"0x4bd8d0b0c1575a7a35915f9af3ef8beb11ad571337ec9b6aca7c88ca7458ef5c",
},
{
"0xdc2690ac6017e32ef17ea219c2a2fd14a2bb73e7a0a253dfd69abba3eb8d7d91",
},
{
"0xf17bf8b7bee09ffc50a401b7ba8e633b9e55eedcf776782f2a55cf7cc5c40aa8",
"0x4f8f1e9e1466609b836dba611a0a24628aea8ee11265f757aa346bde3d88d548",
}
};
AbstractKeyring expect = KeyringFactory.createWithRoleBasedKey(expectedAddress, Arrays.asList(expectedPrivateKeys));
AbstractKeyring actual = KeyringFactory.decrypt(jsonV4, password);
checkValidKeyring(expect, actual);
}
}