1
通過APDU發送JavaCard RSAPublicKey會有什麼好的解決方案? 獲取指數和模塊並將它們打包到一個字節數組中?Javacard發送APDU中的RSA公鑰
通過APDU發送JavaCard RSAPublicKey會有什麼好的解決方案? 獲取指數和模塊並將它們打包到一個字節數組中?Javacard發送APDU中的RSA公鑰
是的,您需要將指數和模數序列化爲一個字節數組。這兩種方法解決您的問題:
//reads the key object and stores it into the buffer
private final short serializeKey(RSAPublicKey key, byte[] buffer, short offset) {
short expLen = key.getExponent(buffer, (short) (offset + 2));
Util.setShort(buffer, offset, expLen);
short modLen = key.getModulus(buffer, (short) (offset + 4 + expLen));
Util.setShort(buffer, offset + 2 + expLen, modLen);
return (short) (4 + expLen + modLen);
}
//reads the key from the buffer and stores it inside the key object
private final short deserializeKey(RSAPublicKey key, byte[] buffer, short offset) {
short expLen = Util.getShort(buffer, offset);
key.setExponent(buffer, (short) (offset + 2), expLen);
short modLen = Util.getShort(buffer, (short) (offset + 2 + expLen));
key.setModulus(buffer, (short) (offset + 4 + expLen), modLen);
return (short) (4 + expLen + modLen);
}