Ⅰ php已经对文件名进行sha1加密了,怎么才能在实现下载文件的时候获得文件原名呢
不可能的,单项散列算法。
解释:
安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准(Digital Signature Standard
DSS)里面定义的数字签名算法(Digital Signature Algorithm
DSA)。对于长度小于2^64位的消息,SHA1会产生一个160位的消息摘要。该算法经过加密专家多年来的发展和改进已日益完善,并被广泛使用。该算
法的思想是接收一段明文,然后以一种不可逆的方式将它转换成一段(通常更小)密文,也可以简单的理解为取一串输入码(称为预映射或信息),并把它们转化为
长度较短、位数固定的输出序列即散列值(也称为信息摘要或信息认证代码)的过程。散列函数值可以说是对明文的一种“指纹”或是“摘要”所以对散列值的数字签名就可以视为对此明文的数字签名
Ⅱ php: sha1和 md5 两种加密的区别
MD5
消息摘要算法5(MD5),把信息分为512比特的分组,并且创建一个128比特的摘要。
SHA-1
安全hash算法(SHA-1),也是基于MD5的,使用一个标准把信息分为512比特的分组,并且创建一个160比特的摘要
Ⅲ 求教PHP和java大神 base64_encode(hash_hmac('sha1',$public_key,$private_key,TRUE)); 转 java
如果你的API服务安全认证协议中要求使用hmac_sha1方法对信息进行编码,
而你的服务是由PHP实现的,客户端是由JAVA实现的,那么为了对签名正确比对,就需要在两者之间建立能匹配的编码方式.
efine('ID','123456');
define('KEY','k123456');
$strToSign = "test_string";
$utf8Str = mb_convert_encoding($strToSign, "UTF-8");
$hmac_sha1_str = base64_encode(hash_hmac("sha1", $utf8Str, KEY));
$signature = urlencode($hmac_sha1_str);
print_r($signature);
JAVA侧需要注意如下几点:
1. hmac_sha1编码结果需要转换成hex格式
2. java中base64的实现和php不一致,其中java并不会在字符串末尾填补=号以把字节数补充为8的整数
3. hmac_sha1并非sha1, hmac_sha1是需要共享密钥的
参考实现如下:
[java] view plain
import java.io.UnsupportedEncodingException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.wicket.util.crypt.Base64UrlSafe;
public class test {
public static void main(String[] args) {
String key = "";
String toHash = "GET"+"\n"+"Thu, 09 Aug 2012 13:33:46 +0000"+"\n"+"/ApiChannel/Report.m";
//String toHashUtf8 = URLEncoder.encode(toHash, "UTF-8");
String res = hmac_sha1(toHash, key);
//System.out.print(res+"\n");
String signature;
try {
signature = new String(Base64UrlSafe.encodeBase64(res.getBytes()),"UTF-8");
signature = appendEqualSign(signature);
System.out.print(signature);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public static String hmac_sha1(String value, String key) {
try {
// Get an hmac_sha1 key from the raw key bytes
byte[] keyBytes = key.getBytes();
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
// Get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(signingKey);
// Compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(value.getBytes());
// Convert raw bytes to Hex
String hexBytes = byte2hex(rawHmac);
return hexBytes;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String byte2hex(final byte[] b){
String hs="";
String stmp="";
for (int n=0; n<b.length; n++){
stmp=(java.lang.Integer.toHexString(b[n] & 0xFF));
if (stmp.length()==1) hs=hs+"0"+stmp;
else hs=hs+stmp;
}
return hs;
}
private static String appendEqualSign(String s){
int len = s.length();
int appendNum = 8 - (int)(len/8);
for (int n=0; n<appendNum; n++){
s += "%3D";
}
return s;
}
}
参考:http://www.iteye.com/topic/1002652
Ⅳ php中shal()函数的用法
加密吧,类似MD5()
一般申请会员,传数据到数据库,那么密码不能是明文,都是md5(密码字符串)后放到数据库中
Ⅳ PHP SHA1解密
sha1()转换成40位的无规则数,但是两次用sha1()得到的40位数是一样的,所以:
比如提交过来的$password,你在验证的时候,查询数据库里是否有相通的字段:select * from ... where password = sha1('$password');
密码输入相同自然能查询到。
Ⅵ php: sha1和 md5 两种加密的区别
要说安全,单一的加密其实安全是差不多的.想安全就要多重加密,
这两个其实来说也没什么太大的区别,只是sha1更长了些
Ⅶ php与c#生成sha1不一致的问题
您好,摘要的结果当然是一样的,不一样的是你在C#里又把结果转换成了Base64的字符串,这当然就不一样了,你又加工了一遍嘛。
FC-5E-03-8D-38-A5-70-32-08-54-41-E7-FE-70-10-B0 这是C#里md5实际的结果和php里的fc 5e 03 8d 38 a57032085441e7fe7010b0 怎么会不一样呢,一个字节一个字节看看。
使用使用toString(value,radix)看看。
Ⅷ sha1加密处理中文时在js和php中不一样怎么办!如何处理!!!
前端对中文进行encodeURI,这样中文就会变成字符,英文和数字,再对其进行sha1加密,就可以和php的一致了,之后在后端用urldecode还原为中文就行了。前端和后端的URL编码函数是不同的需要注意。