Java Code Examples for org.apache.commons.codec.DecoderException#printStackTrace()

The following examples show how to use org.apache.commons.codec.DecoderException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberServiceImpl.java    From product-recommendation-system with MIT License 6 votes vote down vote up
@Override
public boolean validatePsd(String plainPsd, String encryptedPsd) {
	boolean flag = false;
	try {
		// 1.获取密文中的盐
		byte[] salt = Hex.decodeHex(encryptedPsd.substring(0, SALT_SIZE * 2).toCharArray());
		// 2.将盐和plainPsd加密HASH_ITERATIONS次
		byte[] sha1Psd = EncryptUtils.sha1(plainPsd.getBytes(), salt, HASH_ITERATIONS);
		// 3.用Hex来编码
		String sha1Hex = new String(Hex.encodeHex(sha1Psd));
		// 4.拼凑第三步得到的值和密文中的盐
		String psd = encryptedPsd.substring(0, SALT_SIZE * 2) + sha1Hex;
		if (psd.equals(encryptedPsd)) {
			flag = true;
		}
	} catch (DecoderException e) {
		e.printStackTrace();
	}
	
	return flag;
}
 
Example 2
Source File: AdminServiceImpl.java    From product-recommendation-system with MIT License 6 votes vote down vote up
@Override
public boolean validatePsd(String plainPsd, String encryptedPsd) {
	boolean flag = false;
	try {
		// 1.获取密文中的盐
		byte[] salt = Hex.decodeHex(encryptedPsd.substring(0, SALT_SIZE * 2).toCharArray());
		// 2.将盐和plainPsd加密HASH_ITERATIONS次
		byte[] sha1Psd = EncryptUtils.sha1(plainPsd.getBytes(), salt, HASH_ITERATIONS);
		// 3.用Hex来编码
		String sha1Hex = new String(Hex.encodeHex(sha1Psd));
		// 4.拼凑第三步得到的值和密文中的盐
		String psd = encryptedPsd.substring(0, SALT_SIZE * 2) + sha1Hex;
		if (psd.equals(encryptedPsd)) {
			flag = true;
		}
	} catch (DecoderException e) {
		e.printStackTrace();
	}
	
	return flag;
}
 
Example 3
Source File: WpaSupplicantParser.java    From WiFiKeyShare with GNU General Public License v3.0 6 votes vote down vote up
private static String parseToken(String networkSection, String tokenName) {
    if (hasToken(networkSection, tokenName)) {
        List<String> tokenLines = tokenLines(networkSection, tokenName);
        String key = tokenLines.get(0).split("=", 2)[1];

        if (tokenName.equals("ssid")
                || tokenName.equals("psk")
                || tokenName.startsWith("wep_key")) {
            if (key.startsWith("\"")) {
                key = key.replaceAll("^\"", "").replaceAll("\"$", "");
            } else {
                try {
                    key = new String(Hex.decodeHex(key.toCharArray()));
                } catch (DecoderException e) {
                    e.printStackTrace();
                }
            }
        }
        return key;
    }

    return "";
}
 
Example 4
Source File: CharacteristicActivity.java    From GizwitsBLE with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	if (v.getId() == R.id.btn_read) {
		mBle.requestReadCharacteristic(mDeviceAddress, mCharacteristic);
	} else if (v.getId() == R.id.btn_notify) {
		if (mNotifyStarted) {
			mBle.requestStopNotification(mDeviceAddress,
					mCharacteristic);
		} else {
			mBle.requestCharacteristicNotification(mDeviceAddress,
					mCharacteristic);
		}
	} else if (v.getId() == R.id.btn_indicate) {
		mBle.requestIndication(mDeviceAddress, mCharacteristic);
	} else if (v.getId() == R.id.btn_write) {
		String val = et_hex.getText().toString();
		try {
			byte[] data = Hex.decodeHex(val.toCharArray());
			mCharacteristic.setValue(data);
			mBle.requestWriteCharacteristic(mDeviceAddress,
					mCharacteristic, "");
		} catch (DecoderException e) {
			e.printStackTrace();
		}
	}
}
 
Example 5
Source File: EncryptUtils.java    From product-recommendation-system with MIT License 5 votes vote down vote up
/**
 * Hex解码.
 */
public static byte[] decodeHex(String input) {
	try {
		return Hex.decodeHex(input.toCharArray());
	} catch (DecoderException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 6
Source File: EncryptTest.java    From product-recommendation-system with MIT License 5 votes vote down vote up
@Test
public void testHexDecode() {
	String plainPsd = "313233343536";
	try {
		System.out.println(new String(Hex.decodeHex(plainPsd.toCharArray())));
	} catch (DecoderException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 7
Source File: URLCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public String decode(@NonNull String text) {
    setMax(1);
    setConfident(1);
    org.apache.commons.codec.net.URLCodec urlCodec = new org.apache.commons.codec.net.URLCodec();
    try {
        return urlCodec.decode(text);
    } catch (DecoderException e) {
        setConfident(0);
        e.printStackTrace();
        return text;
    }
}
 
Example 8
Source File: MatrixIdCodec.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String decode(String encoded) {
    StringBuilder builder = new StringBuilder();

    Matcher m = DECODE_PATTERN.matcher(encoded);
    int prevEnd = 0;
    while (m.find()) {
        try {
            int start = m.start();
            int end = m.end();
            String sub = encoded.substring(start, end).replaceAll(DELIMITER, "");
            String decoded = new String(Hex.decodeHex(sub.toCharArray()), StandardCharsets.UTF_8);
            builder.append(encoded, prevEnd, start);
            builder.append(decoded);
            prevEnd = end - 1;
        } catch (DecoderException e) {
            e.printStackTrace();
        }
    }
    prevEnd++;
    if (prevEnd < encoded.length()) {
        builder.append(encoded, prevEnd, encoded.length());
    }

    if (builder.length() == 0) {
        return encoded;
    } else {
        return builder.toString();
    }
}
 
Example 9
Source File: BridgeEmailCodec.java    From matrix-appservice-email with GNU Affero General Public License v3.0 5 votes vote down vote up
public String decode(String valueEncoded) {
    StringBuilder builder = new StringBuilder();

    Matcher m = decodePattern.matcher(valueEncoded);
    int prevEnd = 0;
    while (m.find()) {
        try {
            int start = m.start();
            int end = m.end();
            String sub = valueEncoded.substring(start, end).replaceAll(delimiter, "");
            String decoded = new String(Hex.decodeHex(sub.toCharArray()), StandardCharsets.UTF_8);
            builder.append(valueEncoded.substring(prevEnd, start));
            builder.append(decoded);
            prevEnd = end - 1;
        } catch (DecoderException e) {
            e.printStackTrace();
        }
    }
    prevEnd++;
    if (prevEnd < valueEncoded.length()) {
        builder.append(valueEncoded.substring(prevEnd, valueEncoded.length()));
    }

    if (builder.length() == 0) {
        return valueEncoded;
    } else {
        return builder.toString();
    }
}
 
Example 10
Source File: SimpleUtils.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public static String deHex(final String sourceValue) {
	String value="";
	try {
		value=new String(org.apache.commons.codec.binary.Hex.decodeHex( SimpleUtils.getStr(sourceValue, "").toCharArray() ) );
	} catch (DecoderException e) {
		e.printStackTrace();
	}
	return value;
}