「Unity/Csharp/md5」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==サンプルコード== // KeyUtility.md5("hoge"); public class KeyUtility { public static string md5( string srcStr ) { System.Security.Cryptography.MD5 md5 = Sys...」) |
|||
| 行2: | 行2: | ||
// KeyUtility.md5("hoge"); | // KeyUtility.md5("hoge"); | ||
public class KeyUtility { | public class KeyUtility { | ||
| − | + | public static string md5( string srcStr ) { | |
| − | + | System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create(); | |
| − | + | byte[] srcBytes = System.Text.Encoding.UTF8.GetBytes(srcStr); | |
| − | + | byte[] destBytes = md5.ComputeHash(srcBytes); | |
| − | + | System.Text.StringBuilder destStrBuilder; | |
| − | + | destStrBuilder = new System.Text.StringBuilder(); | |
| − | + | foreach (byte curByte in destBytes) { | |
| − | + | destStrBuilder.Append(curByte.ToString("x2")); | |
| − | + | } | |
| − | + | return destStrBuilder.ToString(); | |
| − | + | } | |
} | } | ||
==参考== | ==参考== | ||
http://nanoappli.com/blog/archives/6347 | http://nanoappli.com/blog/archives/6347 | ||
2018年4月29日 (日) 07:01時点における最新版
サンプルコード
// KeyUtility.md5("hoge");
public class KeyUtility {
public static string md5( string srcStr ) {
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] srcBytes = System.Text.Encoding.UTF8.GetBytes(srcStr);
byte[] destBytes = md5.ComputeHash(srcBytes);
System.Text.StringBuilder destStrBuilder;
destStrBuilder = new System.Text.StringBuilder();
foreach (byte curByte in destBytes) {
destStrBuilder.Append(curByte.ToString("x2"));
}
return destStrBuilder.ToString();
}
}
