- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要帮助将此代码转换为 Java 以进行密码比较,并且它必须在 Android 上运行。我对如何添加此 C# 代码中给出的盐特别困惑:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace CMS.Core.Utility
{
public sealed class CMSHashManager
{
private static readonly string _salt = "3D5900AE-111A-45BE-96B3-D9E4606CA793";
private static readonly int _hashIterationsMax = 10;
private CMSHashManager()
{
}
#region Public Methods
//Gets the salted hash value with predetermined iterations.
public static string GetPasswordHash(string plaintextPassword)
{
string hashData = plaintextPassword;
for (int hashLimit = 0; hashLimit < _hashIterationsMax; hashLimit++)
hashData = GetHash(_salt + hashData);
return hashData;
}
//Verifies the hash
public static bool VerifyHashedPassword(string plaintextPassword, string encryptedPassword)
{
string hashData = GetPasswordHash(plaintextPassword);
return encryptedPassword.Equals(hashData);
}
#endregion Public Methods
#region Private Methods
//Gets the hash value of the data using SHA512Managed
private static string GetHash(string unhashedData)
{
byte[] hashData = Encoding.UTF8.GetBytes(unhashedData);
// on server 2003 or higher, can use SHA512CryptoServiceProvider
//SHA512CryptoServiceProvider sha512CryptoServiceProvider = new SHA512CryptoServiceProvider();
SHA512Managed sha512CryptoServiceProvider = new SHA512Managed();
hashData = sha512CryptoServiceProvider.ComputeHash(hashData);
sha512CryptoServiceProvider.Clear();
return Convert.ToBase64String(hashData);
}
#endregion Private Methods
}
}
我已经编写了这个创建 MD5 哈希值的 java 方法:
public String getMD5Password(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest digest = java.security.MessageDigest.getInstance("SHA-512");
digest.update(password.getBytes("UTF-16LE"));
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
}
出于测试目的,您可以使用以下案例:
明文:12345
加密后:NgkuakH7UsCQwGHMQOhVXI3nW6M+1AtREY4Qx35osQo87p/whZIzy8cZU7+R7XnmyzgMzLWSvX+rTiWzfGTPsA==
最佳答案
我尝试重现您的代码。
对于密码test,它会生成以下 BASE64 输出
Q0Y2QkI0MTBFRUJFOTAyNkU1OUZGMUNGMzU0NkYzMkI3NDZFMzE5RjQzNTc0MDM5QjU2MUI2NEQxOTQzNzRGMDRENDM0QzMyQjg3MjMwQkM1N0I0ODFDRDlEODlBNjMxQjMyNjRGQjNBQjAwME YwNjk5Rjc0NUNEQjgzMzY1RkM=
我使用了以下代码:
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
//import javax.xml.bind.DatatypeConverter;
import android.util.Base64;
public class Support {
private static final String SALT = "3D5900AE-111A-45BE-96B3-D9E4606CA793";
private static final int MAX_HASH_ITERATIONS = 10;
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String result = Support.GetPasswordHash("test");
System.out.println(result);
}
public static String GetPasswordHash(String plaintextPassword) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String hashData = plaintextPassword;
for (int hashLimit = 0; hashLimit < MAX_HASH_ITERATIONS; hashLimit++) {
hashData = GetHash(SALT + hashData);
}
return hashData;
}
//Gets the hash value of the data using SHA512Managed
private static String GetHash(String unhashedData) throws NoSuchAlgorithmException, UnsupportedEncodingException {
return getMD5Password(unhashedData);
}
//Verifies the hash
public static boolean VerifyHashedPassword(String plaintextPassword, String encryptedPassword) throws NoSuchAlgorithmException, UnsupportedEncodingException {
String hashData = GetPasswordHash(plaintextPassword);
return encryptedPassword.equals(hashData);
}
public static String getMD5Password(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException{
MessageDigest digest = java.security.MessageDigest.getInstance("SHA-512");
digest.update(password.getBytes("UTF-16LE"));
byte messageDigest[] = digest.digest();
StringBuilder sb = new StringBuilder();
for(int iPos = 0; iPos < messageDigest.length; iPos++) {
String h = Integer.toHexString(0xFF & messageDigest[iPos]);
while (h.length() < 2) {
h = "0" + h;
}
sb.append(h);
}
String md5String = sb.toString().toUpperCase();
String res = Base64.encodeToString(md5String.getBytes(), Base64.DEFAULT);
return res;
}
}
关于java - MD5 SHA512托管 C# 到 Java 代码的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25121868/
我想在 md-toolbar 中使用 mf-tabs,我使用 Sithdown 在 https://github.com/angular/material/issues/1076 中提供的解决方案 它
我是新手,我设法用服务提供的数据实现了我的 md-table。现在我正在尝试实现过滤器、排序和分页功能,但我认为我做错了什么。 这是我的组件: import { Component, OnInit,
我必须打开一个 md-dialog,其中包含一个带有两个选项卡的 md-tab-group。 md-dialog 可以从两个按钮打开,这两个按钮应该打开相应的选项卡。打开 md-dialog 的模板:
我正在尝试做这样的事情: {{item}}
我正在尝试使用 md-datepicker 遍历一个月的时间间隔,因此我创建了这个 codepen 示例以便更好地演示: http://codepen.io/anon/pen/ygBGOg 当单击“P
这是关于 Codepen 的例子. 我正在设置 md-row-height="30px" 然后计算 md-rowspan 使其等于元素数 + 1。(头部加一) {{ t
当我频繁切换 md-tabs 时,Md-tabs 切换正确但多个 md-tab-item 元素同时具有“md-active”类,所以我看不到选项卡的内容是事件的,因为它与其右侧选项卡的内容重叠。 据我
我想将操作放在同一数据行上,我有两个操作,为此我使用按钮和图标作为下面的代码。 {{item.codigo}} {{it
在我的对象列表中,我可以激活/非事件对象。因此,一个图标执行事件操作,另一个图标执行非事件操作,并且两者都在同一个 md-list 中。 This is what i'm tring to do 代码
如前所述 Angular-Material md-autocomplete's documentation : The md-autocomplete uses the the md-virtual-
我也在使用 Angular 1 和 Angular Material 。我想在 ng-repeat 中使用 md-subheader 和多个 md-virtual-repeat-container。您
我正在使用 Angular Material 。 当我创建自己的指令并将其添加到 md-tab-label 时,例如 Label 然后自定义指令也应用于一些“md-dummy-tab”。 但是
我在我的项目中使用 Angular Material 有一段时间了。在使用 md-select 时,我遇到了一个问题,即出现重复的 md-option 值错误。 我知道 md-options 采用唯一
我正在根据单选按钮选择设置自动完成验证 md-require-match = true/false。 默认验证是 md-require-match = true 这样用户应该从自动完成列表中选择一个项
这个问题在这里已经有了答案: Changing capitalization of filenames in Git (11 个答案) 关闭 3 年前。 我使用“readme.md”创建了我的存储库
Github有办法吗?在例如 README.md 中包含 md 文件? # Headline Text [include](File:load_another_md_file_here.md) 它不应
我正在使用 AngularJs 开发这个动态过滤系统,并试图找出如何将 color 和 size 选项转换为在两个下拉列表中(每个类别一个)。 我尝试了以下代码,该代码成功添加了下拉列表以及选择框中的
var app = angular.module('tabsDemo', ['ngMaterial']); app.controller('TabsController',tabsController
在 md-tab 指令内嵌套 md-select 和搜索输入时遇到问题。 有两个问题: 选择框展开后,必须向上滚动才能查看搜索输入 搜索输入实际上不接受任何文本 我做了一个codepen为了更好地说明
我正在尝试处理这个片段,其中自动完成功能嵌入在芯片中。但从自动完成中选择的项目不会转换为筹码。 自动完成的数据采用以下方式:{name:"John Doe", id:"1"} 哪里错了,请指教。 问候
我是一名优秀的程序员,十分优秀!