public EncryptionKeys( @Nullable byte[] adminKey, @Nullable byte[] memberKey, @Nullable byte[] guestKey) { _adminKeyBytes = adminKey; _memberKeyBytes = memberKey; _guestKeyBytes = guestKey; _adminKey = null; _memberKey = null; _guestKey = null; if (_adminKeyBytes != null) { _adminKey = BleUtils.bytesToHexString(_adminKeyBytes); } if (_memberKeyBytes != null) { _memberKey = BleUtils.bytesToHexString(_memberKeyBytes); } if (_guestKeyBytes != null) { _guestKey = BleUtils.bytesToHexString(_guestKeyBytes); } }
public EncryptionKeys( @Nullable String adminKey, @Nullable String memberKey, @Nullable String guestKey) { _adminKey = getKeyFromString(adminKey); _memberKey = getKeyFromString(memberKey); _guestKey = getKeyFromString(guestKey); _adminKeyBytes = null; _memberKeyBytes = null; _guestKeyBytes = null; try { if (_adminKey != null) { _adminKeyBytes = BleUtils.hexStringToBytes(_adminKey); } if (_memberKey != null) { _memberKeyBytes = BleUtils.hexStringToBytes(_memberKey); } if (_guestKey != null) { _guestKeyBytes = BleUtils.hexStringToBytes(_guestKey); } } catch (java.lang.NumberFormatException e) { BleLog.getInstance().LOGe(TAG, "Invalid key format"); e.printStackTrace(); } }
private String getKeyFromString(String key) { if (key == null) { return null; } String retKey = null; if (key.length() == BleBaseEncryption.AES_BLOCK_SIZE * 2) { retKey = key; } if (key.length() == BleBaseEncryption.AES_BLOCK_SIZE) { byte[] keyBytes = key.getBytes(Charset.forName("UTF-8")); retKey = BleUtils.bytesToHexString(keyBytes); } return retKey; }