/// <summary> /// Función encargada de encriptar la contraseña /// </summary> /// <param name="passwordToHash">contraseña sin cifrar</param> /// <returns></returns> public string encryptPassword(string passwordToHash) { string generatedPassword = null; string salt = "0uTl@k"; try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(Encoding.UTF8.GetBytes(salt)); byte[] bytes = md.digest(Encoding.UTF8.GetBytes(passwordToHash)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.Length; i++) { sb.Append(java.lang.Integer.toString((bytes[i] & 0xff) + 0x100, 16).Substring(1)); } generatedPassword = sb.ToString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return(generatedPassword); throw new UnsupportedEncodingException(); }
/// <summary> /// Generate a hash from a source string /// </summary> internal static string genHash(string strSrc) { string strHash = ""; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); sbyte[] inBuf = strSrc.GetBytes("UTF-8"); md.update(inBuf); sbyte[] finalVal = md.digest(); // convert the hash value to string StringBuilder sb = new StringBuilder(finalVal.Length * 2); for (int i = 0; i < finalVal.Length; ++i) { sb.Append(hex2Ascii(((int)finalVal[i] >> 4) & 0x0f)); sb.Append(hex2Ascii((int)finalVal[i] & 0x0f)); } strHash = sb.ToString(); } catch (Exception e) { SqlFsLog.debug(e); } return(strHash); }
/** * Create a MessageDigest using * the javaName (and javaProvider, if not null). */ public MessageDigest createMessageDigest() { try { if (_javaProvider != null) { return(MessageDigest.getInstance(_javaName, _javaProvider)); } else { return(MessageDigest.getInstance(_javaName)); } } catch (NoSuchAlgorithmException ex) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, ex.ToString(), ex); } return(null); } catch (NoSuchProviderException ex) { if (log.isLoggable(Level.FINE)) { log.log(Level.FINE, ex.ToString(), ex); } return(null); } }
protected internal virtual MessageDigest createDigestInstance() { try { return(MessageDigest.getInstance(hashAlgorithmName())); } catch (NoSuchAlgorithmException) { throw new ProcessEngineException("Cannot lookup " + hashAlgorithmName() + " algorithm"); } }
public override void start() { try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { Console.WriteLine("Cannot find MD5", e); } base.start(); }
public HashSumEventStream(EventStream eventStream) { this.eventStream = eventStream; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { // should never happen, does all java runtimes have md5 ?! throw new IllegalStateException(e); } }
private static sbyte[] Hash(sbyte[] salt, sbyte[] password) { try { MessageDigest m = MessageDigest.getInstance(DIGEST_ALGO); m.update(salt, 0, salt.Length); m.update(password, 0, password.Length); return(m.digest()); } catch (NoSuchAlgorithmException e) { throw new Exception("Hash algorithm is not available on this platform: " + e.Message, e); } }
/** * 计算消息摘要。 * @param data 计算摘要的数据。 * @param offset 数据偏移地址。 * @param length 数据长度。 * @return 摘要结果。(16字节) */ public static String md5Str(String str, int offset) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] b = strToToHexByte(str); md5.update(b, offset, b.Length); return(byteArrayToHexString(md5.digest())); } catch (NoSuchAlgorithmException ex) { ex.printStackTrace(); return(null); } }
public override string CalculateSHA1() { MessageDigest md = MessageDigest.getInstance ("SHA"); DataBufferInt dbi = (DataBufferInt) Image.getRaster ().getDataBuffer (); for (int i=0; i<dbi.getNumBanks (); i++) { int [] curBank = dbi.getData (i); for (int j=0; j<curBank.Length; j++) { int x = curBank[j]; md.update ((sbyte) (x & 0xFF)); md.update ((sbyte) ((x>>8) & 0xFF)); md.update ((sbyte) ((x>>16) & 0xFF)); md.update ((sbyte) ((x>>24) & 0xFF)); } } byte [] resdata = (byte[])vmw.common.TypeUtils.ToByteArray(md.digest()); return Convert.ToBase64String (resdata); }
public virtual sbyte[] doSHA1(sbyte[] bytes, int Length) { try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(bytes, 0, Length); sbyte[] sha1Hash = md.digest(); return(sha1Hash); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(null); } }
public virtual sbyte[] doSHA256(sbyte[] bytes, int lenght) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); sbyte[] sha256Hash = new sbyte[40]; md.update(bytes, 0, lenght); sha256Hash = md.digest(); return(sha256Hash); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); return(null); } }
/** * @ * @ * @todo refactor it to separate Handshake class */ public void sendHandshake() { //no text in class plz, mv, to cfg responseByte = ("HTTP/1.1 101 Switching Protocols\r\n" + "WebSocketConnection: Upgrade\r\n" + "Upgrade: websocket\r\n" + "Sec-WebSocket-Accept: " + DatatypeConverter .printBase64Binary( MessageDigest .getInstance("SHA-1") .digest((secWebSocketKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11") .getBytes("UTF-8"))) + "\r\n\r\n") .getBytes("UTF-8"); outputStream.write(responseByte, 0, responseByte.length); }
public virtual int sceNet_lib_384EFE14(TPointer in1Addr, int in1Size, TPointer in2Addr, int in2Size, TPointer outAddr) { if (in2Size > 64) { Console.WriteLine(string.Format("sceNet_lib_384EFE14 not implemented for size=0x{0:X}", in2Size)); } MessageDigest md; try { md = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { Console.WriteLine("sceNet_lib_384EFE14", e); return(-1); } sbyte[] in1 = in1Addr.getArray8(in1Size); sbyte[] in2 = in2Addr.getArray8(in2Size); sbyte[] tmp1 = new sbyte[64]; sbyte[] tmp2 = new sbyte[64]; Array.Copy(in2, 0, tmp1, 0, System.Math.Min(in2Size, tmp1.Length)); Array.Copy(in2, 0, tmp2, 0, System.Math.Min(in2Size, tmp2.Length)); for (int i = 0; i < tmp1.Length; i++) { tmp1[i] = (sbyte)(tmp1[i] ^ 0x36); tmp2[i] = (sbyte)(tmp2[i] ^ 0x5C); } md.update(tmp1); md.update(in1); sbyte[] tmp3 = md.digest(); md.reset(); md.update(tmp2); md.update(tmp3); sbyte[] result = md.digest(); outAddr.setArray(result, 20); return(0); }
// Z:\jsc.svn\examples\javascript\crypto\test\TestWebServiceRSA\TestWebServiceRSA\Program.cs // X:\jsc.svn\examples\javascript\async\AsyncWorkerSourceSHA1\AsyncWorkerSourceSHA1\Application.cs // jsc, did we not do sha1 implementation for js? public override byte[] InternalComputeHash(byte[] buffer) { var value = default(byte[]); try { // http://mindprod.com/jgloss/sha1.html var a = MessageDigest.getInstance("SHA"); a.update(__File.InternalByteArrayToSByteArray(buffer)); value = __File.InternalSByteArrayToByteArray(a.digest()); } catch { throw; } return(value); }
protected internal static int digest(TPointer inAddr, int inSize, TPointer outAddr, string algorithm, int hashLength) { sbyte[] input = inAddr.getArray8(inSize); sbyte[] hash = null; try { MessageDigest md = MessageDigest.getInstance(algorithm); hash = md.digest(input); } catch (Exception e) { // Ignore... Console.WriteLine(string.Format("SceKernelUtilsContext({0}).digest", algorithm), e); } if (hash != null) { outAddr.setArray(hash, hashLength); } return(0); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static byte[] encryptPasswordSHA(byte[] userID, byte[] password, byte[] clientSeed, byte[] serverSeed) throws java.io.IOException internal static sbyte[] encryptPasswordSHA(sbyte[] userID, sbyte[] password, sbyte[] clientSeed, sbyte[] serverSeed) { try { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(userID); md.update(password); sbyte[] token = md.digest(); md.update(token); md.update(serverSeed); md.update(clientSeed); md.update(userID); md.update(SHA_SEQUENCE); return(md.digest()); } catch (NoSuchAlgorithmException e) { IOException io = new IOException("Error loading SHA encryption: " + e); io.initCause(e); throw io; } }
public virtual int result(TPointer ctxAddr, TPointer resultAddr) { sbyte[] hash = null; if (input != null) { try { MessageDigest md = MessageDigest.getInstance(algorithm); hash = md.digest(input); } catch (Exception e) { // Ignore... Console.WriteLine(string.Format("SceKernelUtilsContext({0}).result", algorithm), e); } } if (hash != null) { resultAddr.setArray(hash, hashLength); } return(0); }
/// <summary> /// Create a new digest function for objects. /// </summary> /// <returns>A new digest object.</returns> public static MessageDigest newMessageDigest() { return(MessageDigest.getInstance(HASH_FUNCTION)); }
/** * Appends the authorization string to the StringBuilder. */ private static void appendResponse(StringBuilder sb, string user, string realm, string pass, string requestMethod, string uri, string nonce, string nc, string cnonce, string qop, string algorithm) { MessageDigest resultDigest = null; MessageDigest scratchDigest = null; try { resultDigest = MessageDigest.getInstance(algorithm); scratchDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new QuercusModuleException(e); } { md5(scratchDigest, user); scratchDigest.update((byte)':'); md5(scratchDigest, realm); scratchDigest.update((byte)':'); md5(scratchDigest, pass); update(resultDigest, scratchDigest.digest()); resultDigest.update((byte)':'); } md5(resultDigest, nonce); resultDigest.update((byte)':'); md5(resultDigest, nc); resultDigest.update((byte)':'); md5(resultDigest, cnonce); resultDigest.update((byte)':'); md5(resultDigest, qop); resultDigest.update((byte)':'); { scratchDigest.reset(); md5(scratchDigest, requestMethod); scratchDigest.update((byte)':'); md5(scratchDigest, uri); update(resultDigest, scratchDigest.digest()); } appendHex(sb, resultDigest.digest()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void main(String[] paramArrayOfString) throws Exception public static void Main(string[] paramArrayOfString) { bool @bool; char[] arrayOfChar; char c; string str1; if (paramArrayOfString.Length == 1 || paramArrayOfString.Length == 2) { string[] arrayOfString = paramArrayOfString[0].Split(":", true); str1 = arrayOfString[0]; c = (arrayOfString.Length == 1) ? (char)443 : (char)int.Parse(arrayOfString[1]); string str = (paramArrayOfString.Length == 1) ? "changeit" : paramArrayOfString[1]; arrayOfChar = str.ToCharArray(); } else { Console.WriteLine("Usage: java InstallCert [:port] [passphrase]"); return; } File file = new File("jssecacerts"); if (!file.File) { char c1 = Path.DirectorySeparatorChar; File file1 = new File(System.getProperty("java.home") + c1 + "lib" + c1 + "security"); file = new File(file1, "jssecacerts"); if (!file.File) { file = new File(file1, "cacerts"); } } Console.WriteLine("Loading KeyStore " + file + "..."); FileStream fileInputStream = new FileStream(file, FileMode.Open, FileAccess.Read); KeyStore keyStore = KeyStore.getInstance(KeyStore.DefaultType); keyStore.load(fileInputStream, arrayOfChar); fileInputStream.Close(); SSLContext sSLContext = SSLContext.getInstance("TLS"); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.DefaultAlgorithm); trustManagerFactory.init(keyStore); X509TrustManager x509TrustManager = (X509TrustManager)trustManagerFactory.TrustManagers[0]; SavingTrustManager savingTrustManager = new SavingTrustManager(x509TrustManager); sSLContext.init(null, new TrustManager[] { savingTrustManager }, null); SSLSocketFactory sSLSocketFactory = sSLContext.SocketFactory; Console.WriteLine("Opening connection to " + str1 + ":" + c + "..."); SSLSocket sSLSocket = (SSLSocket)sSLSocketFactory.createSocket(str1, c); sSLSocket.SoTimeout = 10000; try { Console.WriteLine("Starting SSL handshake..."); sSLSocket.startHandshake(); sSLSocket.close(); Console.WriteLine(); Console.WriteLine("No errors, certificate is already trusted"); } catch (SSLException sSLException) { Console.WriteLine(); sSLException.printStackTrace(System.out); } X509Certificate[] arrayOfX509Certificate = savingTrustManager.chain; if (arrayOfX509Certificate == null) { Console.WriteLine("Could not obtain server certificate chain"); return; } StreamReader bufferedReader = new StreamReader(System.in); Console.WriteLine(); Console.WriteLine("Server sent " + arrayOfX509Certificate.Length + " certificate(s):"); Console.WriteLine(); MessageDigest messageDigest1; MessageDigest messageDigest2 = (messageDigest1 = MessageDigest.getInstance("SHA1")).getInstance("MD5"); for (sbyte b = 0; b < arrayOfX509Certificate.Length; b++) { X509Certificate x509Certificate1 = arrayOfX509Certificate[b]; Console.WriteLine(" " + (b + true) + " Subject " + x509Certificate1.SubjectDN); Console.WriteLine(" Issuer " + x509Certificate1.IssuerDN); messageDigest1.update(x509Certificate1.Encoded); Console.WriteLine(" sha1 " + toHexString(messageDigest1.digest())); messageDigest2.update(x509Certificate1.Encoded); Console.WriteLine(" md5 " + toHexString(messageDigest2.digest())); Console.WriteLine(); } Console.WriteLine("Enter certificate to add to trusted keystore or 'q' to quit: [1]"); string str2 = bufferedReader.ReadLine().Trim(); try { @bool = (str2.Length == 0) ? 0 : (int.Parse(str2) - 1); } catch (System.FormatException) { Console.WriteLine("KeyStore not changed"); return; } X509Certificate x509Certificate = arrayOfX509Certificate[@bool]; string str3 = str1 + "-" + (@bool + true); keyStore.setCertificateEntry(str3, x509Certificate); FileStream fileOutputStream = new FileStream("jssecacerts", FileMode.Create, FileAccess.Write); keyStore.store(fileOutputStream, arrayOfChar); fileOutputStream.Close(); Console.WriteLine(); Console.WriteLine(x509Certificate); Console.WriteLine(); Console.WriteLine("Added certificate to keystore 'jssecacerts' using alias '" + str3 + "'"); }
private static MessageDigest CreateSUT() { return(MessageDigest.getInstance("MD5")); }