Commit c719ffce by WeiCong

修改国密加密

parent e38f1a14
......@@ -225,7 +225,10 @@ public class DatabaseLoginContextForELCS extends AbstractLoginContext {
if (dbPassword != null) {
dbPassword = dbPassword.trim();
}
String encodedPassword = ContainerUtils.encodeWithSalt ? passwordFilter.encode(password, userName).trim() : passwordFilter.encode(password).trim();
// String encodedPassword = ContainerUtils.encodeWithSalt ? passwordFilter.encode(password, userName).trim() : passwordFilter.encode(password).trim();
// log.info("password反转回来==="+password+",userName===="+userName);
String encodedPassword = passwordFilter.encode(password, userName).trim();
// log.info("password国密解析==="+encodedPassword);
log.debug("password(input/db)" + dbPassword + "\t" + encodedPassword);
if (!encodedPassword.equals(dbPassword))
return "[Database: NOT Match.]";
......
......@@ -3,58 +3,52 @@
*/
package org.sss.presentation.noui.filter;
import cfca.sadk.util.HashUtil;
import log.Log;
import log.LogFactory;
import org.apache.commons.codec.binary.Base64;
import org.sss.common.model.IFilter;
import org.sss.util.ContainerUtils;
import cfca.sadk.util.HashUtil;
import java.nio.charset.StandardCharsets;
/**
* 密码过滤器实现(国密)
*
* @author Jason.Hoo (latest modification by $Author: hujianxin $)
* @version $Revision: 1014 $ $Date: 2019-01-03 18:23:23 +0800 (Thu, 03 Jan 2019) $
*/
public class PasswordSM2Filter
implements IFilter
{
static final Log log = LogFactory.getLog(PasswordSM2Filter.class);
implements IFilter {
static final Log log = LogFactory.getLog(PasswordSM2Filter.class);
public String decode(String encodedValue)
{
if (ContainerUtils.isEmpty(encodedValue))
return null;
return "**********";
}
public String encode(String value)
{
if (ContainerUtils.isEmpty(value))
return value;
byte[] result = null;
try
{
result = HashUtil.SM2HashMessageByBCWithoutZValue(value.getBytes());
public String decode(String encodedValue) {
if (ContainerUtils.isEmpty(encodedValue))
return null;
return "**********";
}
catch (Exception e)
{
log.error("encode SM2 error.", e);
return null;
public String encode(String value) {
if (ContainerUtils.isEmpty(value))
return value;
byte[] encodedPassword = null;
try {
encodedPassword = HashUtil.SM2HashMessageByBCWithoutZValue(value.getBytes(StandardCharsets.UTF_8));
StringBuffer buf = new StringBuffer();
for (int i = 0; i < encodedPassword.length; i++) {
if ((encodedPassword[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
}
return buf.toString();
} catch (Exception e) {
log.error("encode SM2 error.", e);
return "";
}
}
return new Base64().encodeToString(result).trim();
}
public String encode(String value, String salt)
{
if (ContainerUtils.isEmpty(value))
return value;
value = encode(value);
if (ContainerUtils.isEmpty(salt) || ContainerUtils.isEmpty(value))
return value;
else
return encode(value + salt);
}
public String encode(String value, String salt) {
return encode(salt+value);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment