maven demo

mvn test -Dmaven.test.failure.ignore=true -Dapp.properties.path=conf/area/sz -P profile-A


public class EncryptedPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

private List<String> encryptPropertyNames;

@Override
protected String convertProperty(String propertyName, String propertyValue) {

String propertyValueDecrypt = propertyValue;

if (containsProperty(propertyName)) {
propertyValueDecrypt = PropertyDecryptor.decrypt(propertyValue);
}
return convertPropertyValue(propertyValueDecrypt);
}

private boolean containsProperty(String propertyName) {
return encryptPropertyNames != null && encryptPropertyNames.contains(propertyName);
}

public void setEncryptPropertyNames(List<String> encryptPropertyNames) {
this.encryptPropertyNames = encryptPropertyNames;
}
}






public class PropertyDecryptor {

private static void checkForHex(char c) {
if (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == 'A' || c == 'B' ||
c == 'C' || c == 'D' || c == 'E' || c == 'F') {
return;
}
throw new IllegalArgumentException("Expected hex character for " + Character.toString(c));
}

/**
* @param encryptedText in the form AA[11BB3344 ..] -- All hex numbers Where AA is the key that is XOR'ed againt the
* other numbers to decrypt.
* @return Encrypted string
*/
public static String decrypt(String encryptedText) {

char[] encodedText = encryptedText.toUpperCase().toCharArray();

// First Get the Key.

int key = theConv(encodedText);

char[] textString = new char[encodedText.length / 2 - 1]; // ' - 1'
// since the
// first hex
// is the key

for (int pos = 2; pos < encodedText.length; pos += 2) {

char[] hexNum = {encryptedText.charAt(pos), encryptedText.charAt(pos + 1)};

int x = (theConv(hexNum) ^ key);

char theChar = (char) x;

textString[pos / 2 - 1] = theChar;
}

return new String(textString);
}

private static int theConv(char[] c) {

// Check its Hex
checkForHex(c[0]);
checkForHex(c[1]);

Character hexStr0 = Character.toLowerCase(c[0]);
Character hexStr1 = Character.toLowerCase(c[1]);

int MSB;
int LSB;

// 48 is ASCII value of 0
// 97 is ASCII value of a

if (Character.isDigit(hexStr0)) {
MSB = (hexStr0 - 48);
}
else {
int asciiVal = hexStr0;
MSB = (asciiVal - 97 + 10);
}

if (Character.isDigit(hexStr1)) {
LSB = (hexStr1 - 48);
}
else {
int asciiVal = hexStr1;
LSB = (asciiVal - 97 + 10);
}

return (MSB * 16 + LSB);
}

public static void main(String args[]) {
System.out.println(decrypt(args[0]));
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值