开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1.4K

java-utils/DocSys

forked from Rainy/DocSys
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (22)
标签 (21)
master
dev_DocSys_AddGit_Rainy
DocSys_bld_1.18
DocSys_bld_1.15
DocSys_bld_1.16
DocSys_bld_1.14
dev_DocSys_GD_1.13
DocSys_bld_1.13
DocSys_bld_1.12
DocSys_bld_1.11
DocSys_bld_1.10
dev_DocSys_GD
DocSys_bld_1.09
DocSys_bld_1.08
DocSys_bld_1.07
DocSys_bld_1.06
DocSys_bld_1.05
DocSys_bld_1.04
DocSys_bld_1.03
DocSys_bld_1.02
DocSys_V1.17.10
DocSys_V1.17.9
DocSys_V1.17.8
DocSys_V1.17
DocSys_V1.16
DocSys_V1.15
DocSys_V1.14
DocSys_V1.13
DocSys_V1.12
DocSys_V1.11
DocSys_V1.10
DocSys_V1.09
DocSys_V1.08
DocSys_V1.07
DocSys_V1.06
DocSys_V1.05
DocSys_V1.04
DocSys_V1.03
DocSys_V1.02
DocSys_V1.01
DocSys
/
src
/
util
/
EncryptUtil.java
DocSys
/
src
/
util
/
EncryptUtil.java
EncryptUtil.java 5.92 KB
一键复制 编辑 原始数据 按行查看 历史
zju_rain 提交于 2017年09月28日 11:12 +08:00 . DocSys First Version
package util;
import java.io.IOException;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.util.Calendar;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import util.Encrypt.DES;
public class EncryptUtil {
public static final String PBKDF2_ALGORITHM = "PBKDF2WithHmacSHA1";
// The following constants may be changed without breaking existing hashes.
public static final int SALT_BYTE_SIZE = 24;
public static final int HASH_BYTE_SIZE = 24;
public static final int PBKDF2_ITERATIONS = 1000;
public static final int ITERATION_INDEX = 0;
public static final int SALT_INDEX = 1;
public static final int PBKDF2_INDEX = 2;
/**
* Returns a salted PBKDF2 hash of the password.
*
* @param password the password to hash
* @return a salted PBKDF2 hash of the password
*/
public static String createPassword(String password)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
return createPassword(password.toCharArray());
}
/**
* Returns a salted PBKDF2 hash of the password.
*
* @param password the password to hash
* @return a salted PBKDF2 hash of the password
*/
public static String createPassword(char[] password)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
// Generate a random salt
SecureRandom random = new SecureRandom();
byte[] salt = new byte[SALT_BYTE_SIZE];
random.nextBytes(salt);
// Hash the password
byte[] hash = pbkdf2(password, salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE);
// format iterations:salt:hash
return PBKDF2_ITERATIONS + "@" + HexString.toHex(salt) + "@" + HexString.toHex(hash);
}
/**
* Validates a password using a hash.
*
* @param password the password to check
* @param correctHash the hash of the valid password
* @return true if the password is correct, false if not
*/
public static boolean validatePassword(String password, String correctHash)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
System.out.println("password" + password + " correctHash" + correctHash);
return validatePassword(password.toCharArray(), correctHash);
}
/**
* Validates a password using a hash.
*
* @param password the password to check
* @param correctHash the hash of the valid password
* @return true if the password is correct, false if not
*/
public static boolean validatePassword(char[] password, String correctHash)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
// Decode the hash into its parameters
String[] params = correctHash.split("@");
int iterations = Integer.parseInt(params[ITERATION_INDEX]);
byte[] salt = HexString.fromHex(params[SALT_INDEX]);
byte[] hash = HexString.fromHex(params[PBKDF2_INDEX]);
// Compute the hash of the provided password, using the same salt,
// iteration count, and hash length
byte[] testHash = pbkdf2(password, salt, iterations, hash.length);
// Compare the hashes in constant time. The password is correct if
// both hashes match.
return slowEquals(hash, testHash);
}
public static String createToken(int Expires, String device, String key) throws Exception {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, Expires);
return DES.encrypt( getRandom() + "@" + device + "@" + cal.getTimeInMillis(),key);
}
public static boolean validateToken(Calendar Expires, String device,String token ,String key) throws IOException, Exception {
String content = DES.decrypt(token,key);
String[] pieces = content.split("@");
if( 3 == pieces.length )
{
String forDevice = pieces[1];
long preExpires = Long.parseLong(pieces[2]);
return (forDevice.equals(device) && preExpires > Expires.getTimeInMillis());
}
return false;
}
/**
* Compares two byte arrays in length-constant time. This comparison method
* is used so that password hashes cannot be extracted from an on-line
* system using a timing attack and then attacked off-line.
*
* @param a the first byte array
* @param b the second byte array
* @return true if both byte arrays are the same, false if not
*/
private static boolean slowEquals(byte[] a, byte[] b)
{
int diff = a.length ^ b.length;
for(int i = 0; i < a.length && i < b.length; i++)
diff |= a[i] ^ b[i];
return diff == 0;
}
/**
* Computes the PBKDF2 hash of a password.
*
* @param password the password to hash.
* @param salt the salt
* @param iterations the iteration count (slowness factor)
* @param bytes the length of the hash to compute in bytes
* @return the PBDKF2 hash of the password
*/
private static byte[] pbkdf2(char[] password, byte[] salt, int iterations, int bytes)
throws NoSuchAlgorithmException, InvalidKeySpecException
{
PBEKeySpec spec = new PBEKeySpec(password, salt, iterations, bytes * 8);
SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);
return skf.generateSecret(spec).getEncoded();
}
/**
* 随机数的盐值
* @return
*/
private static String getRandom()
{
//Always use a SecureRandom generator
SecureRandom sr;
try {
sr = SecureRandom.getInstance("SHA1PRNG");
//Create array for salt
byte[] salt = new byte[16];
//Get a random salt
sr.nextBytes(salt);
//return salt
return HexString.toHex(salt);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

DocSys是基于Java开发的Web文件管理系统,旨在为个人和企业用户提供一个简单、方便、安全的文件存储方案,采用Windows桌面系统和Apple手机的用户操作习惯,支持使用SVN和GIT进行历史版本管理、支持文件加密、支持文件内容全文搜索、支持文件预览、支持文件权限管理、支持用户分组管理,支持扩展和定制。GPL 2.0开源协议.
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/java-utils/DocSys.git
git@gitee.com:java-utils/DocSys.git
java-utils
DocSys
DocSys
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /