本文整理汇总了Java中org.ofbiz.base.crypto.DesCrypt类的典型用法代码示例。如果您正苦于以下问题:Java DesCrypt类的具体用法?Java DesCrypt怎么用?Java DesCrypt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DesCrypt类属于org.ofbiz.base.crypto包,在下文中一共展示了DesCrypt类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encryptValue
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
@Override
protected String encryptValue(EncryptMethod encryptMethod, SecretKey key, byte[] objBytes) throws GeneralException {
byte[] saltBytes;
switch (encryptMethod) {
case SALT:
Random random = new SecureRandom();
// random length 5-16
saltBytes = new byte[5 + random.nextInt(11)];
random.nextBytes(saltBytes);
break;
default:
saltBytes = new byte[0];
break;
}
byte[] allBytes = new byte[1 + saltBytes.length + objBytes.length];
allBytes[0] = (byte) saltBytes.length;
System.arraycopy(saltBytes, 0, allBytes, 1, saltBytes.length);
System.arraycopy(objBytes, 0, allBytes, 1 + saltBytes.length, objBytes.length);
String result = Base64.encodeBase64String(DesCrypt.encrypt(key, allBytes));
return result;
}
示例2: EntityCrypto
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
public EntityCrypto(Delegator delegator, String kekText) throws EntityCryptoException {
this.delegator = delegator;
SecretKey kek;
try {
kek = UtilValidate.isNotEmpty(kekText) ? DesCrypt.getDesKey(Base64.decodeBase64(kekText)) : null;
} catch (GeneralException e) {
throw new EntityCryptoException(e);
}
handlers = new StorageHandler[] {
new SaltedBase64StorageHandler(kek),
NormalHashStorageHandler,
OldFunnyHashStorageHandler,
};
}
示例3: decodeKeyBytes
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
@Override
protected byte[] decodeKeyBytes(String keyText) throws GeneralException {
byte[] keyBytes = Base64.decodeBase64(keyText);
if (kek != null) {
keyBytes = DesCrypt.decrypt(kek, keyBytes);
}
return keyBytes;
}
示例4: encodeKey
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
@Override
protected String encodeKey(SecretKey key) throws GeneralException {
byte[] keyBytes = key.getEncoded();
if (kek != null) {
keyBytes = DesCrypt.encrypt(kek, keyBytes);
}
return Base64.encodeBase64String(keyBytes);
}
示例5: decryptValue
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
@Override
protected byte[] decryptValue(SecretKey key, String encryptedString) throws GeneralException {
byte[] allBytes = DesCrypt.decrypt(key, Base64.decodeBase64(encryptedString));
int length = allBytes[0];
byte[] objBytes = new byte[allBytes.length - 1 - length];
System.arraycopy(allBytes, 1 + length, objBytes, 0, objBytes.length);
return objBytes;
}
示例6: encryptValue
import org.ofbiz.base.crypto.DesCrypt; //导入依赖的package包/类
@Override
protected String encryptValue(SecretKey key, byte[] objBytes) throws GeneralException {
Random random = new Random();
// random length 5-16
byte[] saltBytes = new byte[5 + random.nextInt(11)];
random.nextBytes(saltBytes);
byte[] allBytes = new byte[1 + saltBytes.length + objBytes.length];
allBytes[0] = (byte) saltBytes.length;
System.arraycopy(saltBytes, 0, allBytes, 1, saltBytes.length);
System.arraycopy(objBytes, 0, allBytes, 1 + saltBytes.length, objBytes.length);
String result = Base64.encodeBase64String(DesCrypt.encrypt(key, allBytes));
return result;
}