添加加密芯片接口

hdrplus
Aries 1 year ago
parent 745b6b18fe
commit 6794f9943c

@ -816,4 +816,154 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
return res ? JNI_TRUE : JNI_FALSE;
#endif
}
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_queryVersion(
JNIEnv* env,
jclass cls) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
NrsecPort nrsec;
if (!nrsec.Open(port))
{
return JNI_FALSE;
}
std::string version = nrsec.Version();
char buf[128] = { 0 };
strcpy(buf, version.c_str());
nrsec.Close();
return JNI_TRUE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_requestCert(
JNIEnv* env, jclass cls, jint type, jint index, jstring subject) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
NrsecPort nrsec;
if (!nrsec.Open(port))
{
return JNI_FALSE;
}
std::string title_subject = env->GetStringUTFChars(subject, 0);
uint8_t output[1024];
uint16_t len;
bool res = nrsec.SM2cert(type,index,title_subject,output,&len) == 0;
FILE* csr_file = fopen("/sdcard/com.xypower.mpapp/temp/rqcert.csr", "wb");
fwrite(output, sizeof(unsigned char), len, csr_file);
fclose(csr_file);
nrsec.Close();
return res ? JNI_TRUE : JNI_FALSE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
JNIEnv* env, jclass cls, jint index, jstring path, jstring md5) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
NrsecPort nrsec;
if (!nrsec.Open(port))
{
return JNI_FALSE;
}
const char *pathStr = env->GetStringUTFChars(path, 0);
const char *md5Str = env->GetStringUTFChars(md5, 0);
bool res = false;
std::vector<unsigned char> data;
if (readFile(pathStr, data) && !data.empty())
{
res = nrsec.SM2ImportPrivateKey(index, &data[0]) == 0;
}
nrsec.Close();
env->ReleaseStringUTFChars(path, pathStr);
env->ReleaseStringUTFChars(md5, md5Str);
return res ? JNI_TRUE : JNI_FALSE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
JNIEnv* env, jclass cls, jint index) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
NrsecPort nrsec;
if (!nrsec.Open(port))
{
return JNI_FALSE;
}
bool res = false;
std::vector<unsigned char> data(64,0);
res = nrsec.SM2ExportPublicKey(index, &data[0]) == 0;
FILE* Expbkey_file = fopen("/sdcard/device_pbkey.cer", "wb");
fwrite(&data[0], sizeof(unsigned char), data.size(), Expbkey_file);
fclose(Expbkey_file);
nrsec.Close();
return res ? JNI_TRUE : JNI_FALSE;
#endif
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
JNIEnv* env, jclass cls, jint index) {
#ifdef USING_NRSEC
const char *port = "/dev/spidev0.0";
NrsecPort nrsec;
if (!nrsec.Open(port))
{
return JNI_FALSE;
}
bool res = false;
std::vector<unsigned char> data(64,0);
res = nrsec.SM2ExportPrivateKey(index, &data[0]) == 0;
FILE* Exprvkey_file = fopen("/sdcard/device_prvkey.cer", "wb");
fwrite(&data[0], sizeof(unsigned char), data.size(), Exprvkey_file);
fclose(Exprvkey_file);
nrsec.Close();
return res ? JNI_TRUE : JNI_FALSE;
#endif
}

@ -1144,6 +1144,13 @@ cellSignalStrengthGsm.getDbm();
public static native boolean importPublicKey(int index, byte cert[]);
public static native boolean genKeys(int index);
public static native boolean queryVersion();
public static native boolean requestCert(int type, int index, String subject);
public static native boolean importPrivateKeyFile(int index, String path, String md5);
public static native boolean exportPublicKeyFile(int index);
public static native boolean exportPrivateFile(int index);
////////////////////////GPS////////////////////
// private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
private LocationManager mLocationManager;

Loading…
Cancel
Save