我有一个名为public class StatusAES2 {
private static final String key = "12345678912345671234567891234567";
public static void main(String[] args) {
String plainText = "I am plain text";
System.out.println("Original String to encrypt - " + plainText);
String encryptedString = encrypt(plainText);
System.out.println("Encrypted String - " + encryptedString);
String decryptedString = decrypt(encryptedString);
System.out.println("After decryption - " + decryptedString);
}
public static String encrypt(String value) {
try {
byte[] keybytes=key.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(keybytes);
String md5Str=Hex.encodeHexString(thedigest);
IvParameterSpec iv = new IvParameterSpec(new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
keybytes=hextobin(md5Str).getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(keybytes, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes());
String encryptedText=Hex.encodeHexString(encrypted);//bin2hex
return encryptedText;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String decrypt(String encrypted) {
try {
byte[] keybytes=key.getBytes("UTF-8");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] thedigest = md.digest(keybytes);
String md5Str=Hex.encodeHexString(thedigest);
IvParameterSpec iv = new IvParameterSpec(new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
keybytes=hextobin(md5Str).getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(keybytes, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
byte[] original = cipher.doFinal(Hex.decodeHex(encrypted.toCharArray()));
return new String(original);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static String hextobin(String s) throws DecoderException, UnsupportedEncodingException {
int length=s.length();
int count=0;
String binString="";
while(count<length){
int c=count+2;
String subs=s.substring(count,c);
String packedString="";
byte[] somevar = DatatypeConverter.parseHexBinary(subs);
byte[] bytes = Hex.decodeHex(subs.toCharArray());
packedString=new String(bytes, "UTF-8");
if (count==0){
binString=packedString;
}else {
binString=binString+packedString;
}
count=count+2;
}
return binString;
}
}
的视图,在该视图下,我有两个分别称为Reports
和Races
的视图。我将这两个视图称为Sire
页面内的部分视图。
当用户在地址栏中键入Reports
时,它将作为主要视图的http://localhost:53987/Reports/Reports#
和Races
加载为Sire
中的局部视图。但是我想要的是,当用户在地址栏中输入Reports
时,应该将其重定向到http://localhost:53987/Races/Races#
。
任何人都可以建议我如何实现这一目标。
http://localhost:53987/Reports/Reports#
视图
Reports
答案 0 :(得分:1)
如果您所做的只是使用@Html.Partial()
渲染这些部分,则您的控制器方法不是必需的,您可以删除它们(如果用户尝试导航到这些部分,则会得到404: Not Found
网址)。
但是,如果您使用@Html.Action()
来渲染它们(因为必须在控制器中执行一些代码来生成部分代码),则这些方法应标记为[ChildActionOnly]
属性(阻止用户导航到他们。
如果您确实希望允许用户在地址栏中输入这些网址,但重定向到../Reports/Reports
,则可以为他们创建特定的路由定义,例如
routes.MapRoute(
name: "Races",
url: "Races/Races",
defaults: new { controller = "Report", action = "Report" }
);
,并在其他任何匹配的路线之前找到它们。