概述
VeChain芯片验证SDK包含了VeChain NFC芯片验证SDK,VeChain RFID芯片验证SDK以及根据您的设置收集温度,湿度和加速度数据的VeChain Sensor SDk,它可以确保温度,湿度和加速度数据安全可靠并可以被验证。
首次使用
步骤1: 注册App
登陆ToolChain并注册您的应用。联系toolchainsupport@vechain.com以获得更多支持。
-
“Android包名” - 该ID唯一标识您在设备上的应用。 您的应用程序ID是通过模块的build.gradle文件中的applicationId属性定义的,如下所示:
android { defaultConfig { applicationId "com.vechain.user" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" } ... }
-
“Andorid 签名” - 输入您的APP签名(下载“签名工具”以在手机上安装APP签名)。
登陆ToolChain,并记录“Verify ID”以进行SDK注册。
VeChainNFCSDK.registerSDK("Verify ID");
步骤2: 上传CSR文件
- 生成CSR文件: How to generate a csr file.
- 上传CSR文件:
步骤3: 下载证书
此“证书”稍后将用作SDK中的参数。
更多详细信息,请参见:附录A:常见问题#如何签署ChallengeID
开始
要求
1.该SDK将运行的最低Android API级别为19(= Android 5.0), 2.具有NFC功能的Android设备。
手工导入
1 > 解压缩VeChainVerifySDK.zip,您将看到如下列表。
将sdkenc放在主模块下,并在主模块中创建libs,然后将vechain-verify-sdk.aar放在libs文件夹下。
2 > 您还需要将以下内容添加到** app/build.gradle**文件中。
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation(name: 'vechain-verify-sdk', ext: 'aar')
compileOnly files('sdkenc/classes.jar')
}
3 > 设置
继承android.app.Application类并实现以下方法:
import com.shell.SdkManager;
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
SdkManager.initSdkManager(this);
}
}
自定义Application类必须在AndroidManifest.xml中注册:
<application
android:name=".MyApplication"
...>
...
</application>
包装confusion
Add the following lines to the proguard-rules.pro:
#sdk
-keep class com.vechain.** { *; }
-dontwarn com.vechain.**
-keep class com.ijiami.** { *;}
-dontwarn com.ijiami.**
-keep class com.baidu.** { *;}
-keep class com.google.android.gms.** { *;}
-keep class com.google.firebase.** { *;}
-keep class com.tbruyelle.**
##---------------Begin: proguard configuration for Okhttp ----------
# Okhttp3
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-keep class okio.** { *; }
-keep class okhttp3.** { *; }
##---------------end: proguard configuration for Okhttp ----------
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep class com.google.gson.** { *;}
##---------------End: proguard configuration for Gson ----------
##---------------Begin: proguard configuration for Retrofit ----------
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
-keep class retrofit2.** { *; }
##---------------End: proguard configuration for Retrofit ----------
##---------------Begin: proguard configuration for RxJava ----------
#rxbinding
-keep class com.jakewharton.**
-keep class com.squareup.**
-keep class com.tbruyelle.**
-keep class com.trello.**
-keep class io.reactivex.** { *;}
-keep class org.hamcrest.**
-keep class org.reactivestreams.**
#-keepattributes Signature-keepattributes Exceptions
#RxJava RxAndroid
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
##---------------End: proguard configuration for RxJava ----------
附录 A: 常见问题
1. 如何签署ChallengeID
您有两种方法来签署ChallengeID
参数
1. certString : 打开从ToolChain下载的证书(xxx.pem文件),在开始和结束行之间复制内容。
2. certKey : 打开终端并输入以下命令: openssl ec -noout -text -in yourkey.key
删除所有priv的冒号。有时,OpenSSL在私有部分的前面添加了一个空字节(0x00),您必须去除所有的前置零字节。
私钥必须为32个字节,并且不能以0x00开头。
cdab7b2f80d0114ab8a55463a84df26ead9b2c87ff9df2fbb7b8842c63479360
3. challengeId :
VeChain服务在回调SignAction#sign()中提供。
方法 1:
Sign ChallengeId local -从 示例应用程序下载Signlib并调用方法com.vechain.tools.signlib.CertUtils.getSignature(String certString,String certKey,String ChallengeId以获取签名。
package com.vechain.tools.signlib.cert;
public class CertUtils {
/**
* build signature
* @param certString
* @param certKey
* @param challengeId
* @return signature
*/
public static String getSignature(String certString, String certKey, String challengeId) {
return signature;
} k
}
方法 2:
从服务器上签名ChallengeId - 将您的证书和私钥保存在自己的服务器上,然后返回在服务器上签名的签名。
注意:即使您未能从服务器获取签名,也请调用此函数 SignNotifier.onSignResult(“”);
public class MySignAction implements SignAction {
@Override
public void sign(Context context, String challengeId, SignNotifier signNotifier) {
String certString = "Your certificate string";
String privateKeyString = "Your private key";
//More Detail about how to sign the challengeId and get signature, refers to Appendix A: FAQ - How to Sign ChallengeID
String signature = CertUtils.getSignInfo(certString, privateKeyString, challengeId);
signNotifier.onSignResult(signature, "");
}
}
2. 检查NFC的可用性
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) return; // NFC not available on this device
}
3. 检查是否启用了NFC
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter != null) {
//Applications can use this to check if NFC is enabled. Applications can request Settings UI allowing the user to toggle NFC using:
boolean isEnabled = nfcAdapter.isEnabled();
};
}
评论
0 条评论
请登录写评论。