• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SCryptUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.lambdaworks.crypto.SCryptUtil的典型用法代码示例。如果您正苦于以下问题:Java SCryptUtil类的具体用法?Java SCryptUtil怎么用?Java SCryptUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SCryptUtil类属于com.lambdaworks.crypto包,在下文中一共展示了SCryptUtil类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRegisterNewUser

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
/**
 * Integration test that stores User into the database, then reads it from the database
 * and verifies if password was correctly hashed.
 */
@Transactional
@Test
   public void testRegisterNewUser() {
	final String userName = "someone";
	final String password = "somepass";
	userService.registerNewUser(new User("[email protected]", userName, password));
	User user = userRepository.findByUserName(userName);
	Assert.assertNotNull(user);
	Assert.assertTrue(SCryptUtil.check(password, user.getPassword()));
	//Verifying interaction with a mocked bean
	verify(statisticsService, times(1)).recalculateStatisticReports();
}
 
开发者ID:knes1,项目名称:springmockedtests,代码行数:17,代码来源:UserServiceImplIntegrationTest.java


示例2: updateUserPassword

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
public void updateUserPassword(int id, String oldPassword, String newPassword) {
    final String scrypt = SCryptUtil.scrypt(newPassword, 2 << 14, 8, 1);

    if (!PASSWORD_PATTERN.matcher(newPassword).matches()) {
        throw new RakamException("Password is not valid. Your password must contain at least one lowercase character, uppercase character and digit and be at least 8 characters. ", BAD_REQUEST);
    }

    if (config.getHashPassword()) {
        oldPassword = CryptUtil.encryptWithHMacSHA1(oldPassword, encryptionConfig.getSecretKey());
    }

    try (Handle handle = dbi.open()) {
        String hashedPass = handle.createQuery("SELECT password FROM web_user WHERE id = :id")
                .bind("id", id).map(StringMapper.FIRST).first();
        if (hashedPass == null) {
            throw new RakamException("User does not exist", BAD_REQUEST);
        }
        if (!SCryptUtil.check(oldPassword, hashedPass)) {
            throw new RakamException("Password is wrong", BAD_REQUEST);
        }
        handle.createStatement("UPDATE web_user SET password = :password WHERE id = :id")
                .bind("id", id)
                .bind("password", scrypt).execute();
    }
}
 
开发者ID:rakam-io,项目名称:rakam,代码行数:26,代码来源:WebUserService.java


示例3: checkInputs

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
private boolean checkInputs() {
    boolean result = true;

    if (masterPassword.getText() == null || masterPassword.getText().toString().equals("")) {
        result = false;
        masterPassword.setError(getActivity().getString(R.string.errorEmpty));
    } else if (fullName.getText() == null || fullName.getText().toString().equals("")) {
        result = false;
        fullName.setError(getActivity().getString(R.string.errorEmpty));
    } else if (defaultPrefs.verifyPassword()) {
        try {
            result = SCryptUtil
                    .check(masterPassword.getText().toString(), defaultPrefs.masterPasswordHash());
            if (!result) {
                masterPassword.setError(getActivity().getString(R.string.error_incorrectPassword));
            }
        } catch (Exception e) {
            result = false;
            defaultPrefs.masterPasswordHash(null);
            defaultPrefs.verifyPassword(false);
            VerificationFailedDialog verificationFailedDialog = new VerificationFailedDialog();
            verificationFailedDialog.show(getActivity().getSupportFragmentManager(), null);
        }
    }
    return result;
}
 
开发者ID:dkunzler,项目名称:masterpassword,代码行数:27,代码来源:LoginFragment.java


示例4: changePassword

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
@ExpectPermission(Permission.UPDATE_PROFILE)
@RequestMapping(value = "/api/self/password", method = RequestMethod.POST)
public int changePassword(UserWithPermission user, @RequestBody PasswordChange passwordChange) {
    String currentHashedPassword = userRepository.getHashedPassword(user.getProvider(), user.getUsername());

    Validate.isTrue(SCryptUtil.check(passwordChange.getCurrentPassword(), currentHashedPassword));

    return userService.changePassword(user.getId(), passwordChange.getNewPassword());
}
 
开发者ID:digitalfondue,项目名称:lavagna,代码行数:10,代码来源:UserController.java


示例5: encode

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
@Override
public String encode(String password) {
	long time = System.currentTimeMillis();
	String result = SCryptUtil.scrypt(password, complexity, 8, 1);
	log.info("It took {} ms to encode the password.", System.currentTimeMillis() - time);
	return result;
}
 
开发者ID:knes1,项目名称:springmockedtests,代码行数:8,代码来源:SCryptPasswordEncoder.java


示例6: verify

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
public boolean verify(String password, PasswordResponse response) {
    if (response.getAlgorithm() == Algorithm.BCRYPT) {
        return BCrypt.checkpw(password, response.getHash());
    }

    if (response.getAlgorithm() == Algorithm.SCRYPT) {
        return SCryptUtil.check(password, response.getHash());
    }

    if (response.getAlgorithm() == Algorithm.PBKDF2) {
        if (response.getAlgorithmDetails().getIterations() > MAX_PKBDF2_ITERATIONS) {
            throw new IllegalArgumentException("Iterations should not exceed " + MAX_PKBDF2_ITERATIONS);
        }
        byte[] hash = Base64.decodeBase64(response.getHash());
        PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), response.getSalt().getBytes(), response
                .getAlgorithmDetails().getIterations(), response.getAlgorithmDetails().getKeySize());
        try {
            SecretKeyFactory skf = PBKDF2Algorithms.getSecretKeyFactory("PBKDF2WithHmac" + response.getAlgorithmDetails().getHashFunction().replace("-", ""));
            byte[] expectedHash = skf.generateSecret(spec).getEncoded();
            return Arrays.equals(hash, expectedHash);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }

    return true;
}
 
开发者ID:Glamdring,项目名称:saltedhashed,代码行数:28,代码来源:Verifier.java


示例7: scryptTest

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
@Test
public void scryptTest() {
    String password = PasswordUtils.getRandomPassword();
    String hash = SCryptUtil.scrypt(password, 2, 2, 2);
    PasswordResponse response = new PasswordResponse();
    response.setAlgorithm(Algorithm.SCRYPT);
    response.setHash(hash);

    Assert.assertTrue(verifier.verify(password, response));
    Assert.assertFalse(verifier.verify(password + " ", response));
}
 
开发者ID:Glamdring,项目名称:saltedhashed,代码行数:12,代码来源:VerifierTest.java


示例8: Exception

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
public static Boolean check
	( String Passphrase
	, String Hash
	, String Algorithm
	)
throws Exception
{
	switch
		( Algorithm == null
		? Utils.identifyAlgorithm(Hash)
		: Utils.Algorithm.fromString(Algorithm)
		)
	{

		case bcrypt:
			return BCrypt.checkpw
				( Passphrase
				, Hash
				);

		case pbkdf2:
			return PasswordHash.validatePassword
				( Passphrase
				, Hash
				);

		case scrypt:
			return SCryptUtil.check
				( Passphrase
				, Hash
				);

		default:
			throw new Exception("Unsupported Algorithm");

	}
}
 
开发者ID:boughtonp,项目名称:cfpassphrase,代码行数:38,代码来源:Impl.java


示例9: authenticate

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
private boolean authenticate(final String username, final String password) {
    String hashed = userRepository.getHashedPassword(USER_PROVIDER, username);

    return SCryptUtil.check(password, hashed);
}
 
开发者ID:digitalfondue,项目名称:lavagna,代码行数:6,代码来源:PasswordLogin.java


示例10: hashPassword

import com.lambdaworks.crypto.SCryptUtil; //导入依赖的package包/类
private static String hashPassword(String password) {
 return SCryptUtil.scrypt(password, 2 << 14, 8, 1);
}
 
开发者ID:digitalfondue,项目名称:lavagna,代码行数:4,代码来源:UserService.java



注:本文中的com.lambdaworks.crypto.SCryptUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MQVersion类代码示例发布时间:2022-05-22
下一篇:
Java ConcurrencyUtil类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap