Java 语句问题 请问下 key iv是如何怎么运算 看不懂Java啊 请大神帮忙
paramString1=13101102323paramString2=5201314publicstaticStringaz(StringparamString1,S...
paramString1 = 13101102323
paramString2 = 5201314
public static String az(String paramString1, String paramString2)
{
Object localObject = "";
byte[] arrayOfByte1 = new byte[8];
try
{
byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
if (arrayOfByte2.length < 8)
{
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, arrayOfByte2.length);
for (int i = arrayOfByte2.length; i < 8; i++)
arrayOfByte1[i] = 0;
}
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, 8);
Cipher localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
localCipher.init(1, new SecretKeySpec(arrayOfByte1, "DES"), new IvParameterSpec(arrayOfByte1));
String str = d.h(localCipher.doFinal(paramString2.getBytes("UTF-8")));
localObject = str;
return localObject;
}
catch (Exception localException)
{
while (true)
localException.printStackTrace();
}
}
}
请问下
paramString1 = 13101102323
paramString2 = 5201314
key iv如何计算的啊 不懂Java啊大神 展开
paramString2 = 5201314
public static String az(String paramString1, String paramString2)
{
Object localObject = "";
byte[] arrayOfByte1 = new byte[8];
try
{
byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
if (arrayOfByte2.length < 8)
{
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, arrayOfByte2.length);
for (int i = arrayOfByte2.length; i < 8; i++)
arrayOfByte1[i] = 0;
}
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, 8);
Cipher localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
localCipher.init(1, new SecretKeySpec(arrayOfByte1, "DES"), new IvParameterSpec(arrayOfByte1));
String str = d.h(localCipher.doFinal(paramString2.getBytes("UTF-8")));
localObject = str;
return localObject;
}
catch (Exception localException)
{
while (true)
localException.printStackTrace();
}
}
}
请问下
paramString1 = 13101102323
paramString2 = 5201314
key iv如何计算的啊 不懂Java啊大神 展开
1个回答
展开全部
key iv是对称算法么?没看懂不过给你一个注释好的代码
public static String az(String paramString1, String paramString2) {
//声明object对象
Object localObject = "";
//声明8位的byte对象
byte[] arrayOfByte1 = new byte[8];
try {
//转换编码格式为UTF-8
byte[] arrayOfByte2 = paramString1.getBytes("UTF-8");
//判断长度是否为8
if (arrayOfByte2.length < 8) {
//为使处理字符长度为8位,进行数组复制将arrayOfByte2的值复制给arrayOfByte1
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0,
arrayOfByte2.length);
//为arrayOfByte1数组空位补0
for (int i = arrayOfByte2.length; i < 8; i++)
arrayOfByte1[i] = 0;
}
//为使处理字符长度为8位,进行数组复制将arrayOfByte2的值复制给arrayOfByte1
System.arraycopy(arrayOfByte2, 0, arrayOfByte1, 0, 8);
//声明加密处理类,并指定转换名称
Cipher localCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
//用密钥和向量初始化此加密对象
localCipher.init(1, new SecretKeySpec(arrayOfByte1, "DES"),
new IvParameterSpec(arrayOfByte1));
//???不懂????
String str = d
.h(localCipher.doFinal(paramString2.getBytes("UTF-8")));
localObject = str;
return localObject;
} catch (Exception localException) {
while (true)
localException.printStackTrace();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询