本文整理汇总了Java中org.apache.commons.codec.digest.Crypt类的典型用法代码示例。如果您正苦于以下问题:Java Crypt类的具体用法?Java Crypt怎么用?Java Crypt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Crypt类属于org.apache.commons.codec.digest包,在下文中一共展示了Crypt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isHashCorrect
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static boolean isHashCorrect(final String plainToken, final String hash) {
if(plainToken == null || hash == null){
return false;
}
final String check = Crypt.crypt(plainToken, hash);
return hash.equals(check);
}
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:9,代码来源:CryptUtil.java
示例2: generateSalt
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public String generateSalt(String password) {
// Password hash format comes from crypt(3) using SHA-512,
// which is $6$<salt>$<hashed_word>
// We need to save the salt portion so that the hash can be
// consistently generated across requests.
final String passwordHash = Crypt.crypt(password);
return passwordHash.substring(0, passwordHash.lastIndexOf("$"));
}
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:9,代码来源:CryptSaltFactory.java
示例3: canCreateViewFromEntity
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
@Test
public void canCreateViewFromEntity() throws IOException {
final UUID uuid = UUID.randomUUID();
final String salt = new CryptSaltFactory().generateSalt("test-password");
final String passwordHash = Crypt.crypt("test-password", salt);
final UserCredentialVersion userCredential = mock(UserCredentialVersion.class);
when(userCredential.getName()).thenReturn("/foo");
when(userCredential.getUuid()).thenReturn(uuid);
when(userCredential.getCredentialType()).thenReturn("user");
when(userCredential.getPassword()).thenReturn("test-password");
when(userCredential.getUsername()).thenReturn("test-username");
when(userCredential.getSalt()).thenReturn(salt);
UserView actual = (UserView) UserView.fromEntity(userCredential);
assertThat(JsonTestHelper.serializeToString(actual), equalTo("{"
+ "\"type\":\"user\","
+ "\"version_created_at\":null,"
+ "\"id\":\"" + uuid.toString() + "\","
+ "\"name\":\"/foo\","
+ "\"value\":{"
+ "\"username\":\"test-username\","
+ "\"password\":\"test-password\","
+ "\"password_hash\":\"" + passwordHash + "\""
+ "}}"));
}
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:28,代码来源:UserViewTest.java
示例4: validatePassword
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
/**
* htpasswd supports a few other password encryption schemes than the StandardCredentialsRealm.
*
* @param requestCredentials
* @param storedCredentials
* @return true if the request password validates against the stored password
*/
@Override
protected boolean validatePassword(StandardCredentials requestCredentials, StandardCredentials storedCredentials) {
final String storedPassword = storedCredentials.getPassword();
final String username = requestCredentials.getUsername();
final String password = requestCredentials.getPassword();
boolean authenticated = false;
// test Apache MD5 variant encrypted password
if (storedPassword.startsWith("$apr1$")) {
if (storedPassword.equals(Md5Crypt.apr1Crypt(password, storedPassword))) {
log.trace("Apache MD5 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Unsalted SHA password
else if (storedPassword.startsWith("{SHA}")) {
String password64 = Base64.encodeBase64String(DigestUtils.sha1(password));
if (storedPassword.substring("{SHA}".length()).equals(password64)) {
log.trace("Unsalted SHA-1 encoded password matched for user '{}'", username);
authenticated = true;
}
}
// test Libc Crypt password
else if (!isAllowClearTextPasswords() && storedPassword.equals(Crypt.crypt(password, storedPassword))) {
log.trace("Libc crypt encoded password matched for user '{}'", username);
authenticated = true;
}
// test Clear Text password
else if (isAllowClearTextPasswords() && storedPassword.equals(password)) {
log.trace("Clear text password matched for user '{}'", username);
authenticated = true;
}
return authenticated;
}
开发者ID:gitblit,项目名称:fathom,代码行数:43,代码来源:HtpasswdRealm.java
示例5: verifyMD5Crypt
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
private boolean verifyMD5Crypt(String token, String password) {
String[] parts = token.split("\\$");
if (parts.length != 4) {
return false;
}
if (!parts[1].equals("6")) {
return false;
}
String salt = parts[2];
String myHashString = Crypt.crypt(password, "$6$" + salt + "$");
return myHashString.equals(token);
}
开发者ID:RomanKreisel,项目名称:Faktotum,代码行数:13,代码来源:CryptBean.java
示例6: incrementToken
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
@Override
public boolean incrementToken() throws IOException {
for (;;) {
if (!input.incrementToken())
return false;
String term = salt == null ? Crypt.crypt(termAtt.toString())
: Crypt.crypt(termAtt.toString(), salt);
createToken(term);
return true;
}
}
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:12,代码来源:CryptFilter.java
示例7: encryptPassword
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
/**
* encrypts the given credentials based on the algorithm name and optional salt
*
* @param credentials the credentials to be encrypted
* @param algorithm the algorithm to be used for encrypting the credentials
* @param salt value to be used as salt (optional)
* @return the encrypted credentials
*/
private static byte[] encryptPassword( byte[] credentials, LdapSecurityConstants algorithm, byte[] salt )
{
switch ( algorithm )
{
case HASH_METHOD_SHA:
case HASH_METHOD_SSHA:
return digest( LdapSecurityConstants.HASH_METHOD_SHA, credentials, salt );
case HASH_METHOD_SHA256:
case HASH_METHOD_SSHA256:
return digest( LdapSecurityConstants.HASH_METHOD_SHA256, credentials, salt );
case HASH_METHOD_SHA384:
case HASH_METHOD_SSHA384:
return digest( LdapSecurityConstants.HASH_METHOD_SHA384, credentials, salt );
case HASH_METHOD_SHA512:
case HASH_METHOD_SSHA512:
return digest( LdapSecurityConstants.HASH_METHOD_SHA512, credentials, salt );
case HASH_METHOD_MD5:
case HASH_METHOD_SMD5:
return digest( LdapSecurityConstants.HASH_METHOD_MD5, credentials, salt );
case HASH_METHOD_CRYPT:
String saltWithCrypted = Crypt.crypt( Strings.utf8ToString( credentials ), Strings
.utf8ToString( salt ) );
String crypted = saltWithCrypted.substring( 2 );
return Strings.getBytesUtf8( crypted );
case HASH_METHOD_CRYPT_MD5:
case HASH_METHOD_CRYPT_SHA256:
case HASH_METHOD_CRYPT_SHA512:
String saltWithCrypted2 = Crypt.crypt( Strings.utf8ToString( credentials ),
algorithm.getSubPrefix() + Strings.utf8ToString( salt ) );
String crypted2 = saltWithCrypted2.substring( saltWithCrypted2.lastIndexOf( '$' ) + 1 );
return Strings.getBytesUtf8( crypted2 );
case HASH_METHOD_CRYPT_BCRYPT:
String crypted3 = BCrypt.hashPw( Strings.utf8ToString( credentials ), Strings.utf8ToString( salt ) );
return Strings.getBytesUtf8( crypted3.substring( crypted3.length() - 31 ) );
case HASH_METHOD_PKCS5S2:
return generatePbkdf2Hash( credentials, algorithm, salt );
default:
return credentials;
}
}
开发者ID:apache,项目名称:directory-ldap-api,代码行数:58,代码来源:PasswordUtil.java
示例8: getAuthEmailHash
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static String getAuthEmailHash(String authEmail) {
return Crypt.crypt(authEmail);
}
开发者ID:daflockinger,项目名称:poppynotes,代码行数:4,代码来源:CryptoUtils.java
示例9: checkPasswordWithHash
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static boolean checkPasswordWithHash(String enteredPassword, String storedHash) {
return storedHash.equals(Crypt.crypt(enteredPassword, storedHash));
}
开发者ID:daflockinger,项目名称:poppynotes,代码行数:4,代码来源:CryptoUtils.java
示例10: generateHash
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static String generateHash(final String token) {
return Crypt.crypt(token);
}
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:4,代码来源:CryptUtil.java
示例11: getPasswordHash
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
@JsonProperty(value = "password_hash", access = READ_ONLY)
@SuppressWarnings("unused")
public String getPasswordHash() {
return Crypt.crypt(getPassword(), getSalt());
}
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:6,代码来源:UserCredentialValue.java
示例12: crypt
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static String crypt(String key, String salt) {
return Crypt.crypt(key, salt);
}
开发者ID:metno,项目名称:poseidon-rest,代码行数:4,代码来源:KundedbCryptService.java
示例13: validateCryptPassword
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
private static boolean validateCryptPassword(String hashed, String plain) {
String result = Crypt.crypt(plain, hashed);
return hashed.equals(result);
}
开发者ID:kkesha,项目名称:jenkins-htpasswd-auth,代码行数:5,代码来源:HtPasswdFile.java
示例14: cryptCheck
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
public static boolean cryptCheck(String plaintext, String hashed) {
return hashed.equals(Crypt.crypt(plaintext, hashed));
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:4,代码来源:Digest.java
示例15: cryptMD5Crypt
import org.apache.commons.codec.digest.Crypt; //导入依赖的package包/类
private String cryptMD5Crypt(String password) {
return Crypt.crypt(password);
}
开发者ID:RomanKreisel,项目名称:Faktotum,代码行数:4,代码来源:CryptBean.java
注:本文中的org.apache.commons.codec.digest.Crypt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论