このコード スニペットを Java から .net、この場合は vb.net に変換するのに少し問題がありますが、c# から vb に変換できれば幸いです。
「final boolean useStandardEnding」で始まる行までは問題ありません。これは簡単な部分でした.全体像を示すために、関数全体のコードを含めました。次の行と IF ステートメントを試みましたが、XOR について話し始めました。そのためのコーディングをどこから始めればよいかわかりません。XOR の概念は理解していますが、これまでのところ、その必要はありません実際にコーディングして..
どんな助けでも大歓迎です。
public class TokenDecode {
/**
* Method to decode the User token
*
* @param UserId
* @return long - unique decoded id
*/
public static long decode(final String UserId) {
final int FILL_CHAR_EQUAL = 1;
int type = 0;
if (UserId == null) {
throw new IllegalArgumentException("UserId can't be null");
}
if (UserId.endsWith("=")) {
// new encoding
type = 1;
} else {
// old encoding
type = 2;
}
final boolean useStandardEnding = (type == FILL_CHAR_EQUAL);
byte[] bytes = Base64.decode(UserId, useStandardEnding);
if (bytes.length < 40) {
throw new IllegalArgumentException(
"Base64 decoded length of UserId should be 40 (Actual="
+ bytes.length + ";UserId=" + UserId + ")");
}
// exclusive or
byte[] xor = { (byte) 0xa0, (byte) 0xb2, (byte) 0x91, (byte) 0x20 };
int cnt = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 4; j++) {
bytes[cnt] = (byte) (bytes[cnt] ^ xor[j]);
cnt++;
}
xor[3] += 4;
}
// rotate right 2 entities
final byte[] buffer = new byte[8];
System.arraycopy(bytes, 32, buffer, 0, 8);
System.arraycopy(bytes, 0, bytes, 8, 32);
System.arraycopy(buffer, 0, bytes, 0, 8);
// remove leading '=' and convert to int
String str = new String(bytes);
final int pos = str.lastIndexOf('=');
str = str.substring(pos + 1);
// Added to remove the extra spaces in the userid
// Integration.
str = (str == null) ? null : str.trim();
return Long.parseLong(str);
}
}
ありがとう