1. Наш канал codeby в telegram. Пишем об информационной безопасности, методах защиты информации, о программировании. Не пропускай новости с кодебай, будь в тренде ! Подробнее ...

    Скрыть объявление

Java Hash Sha 512

Тема в разделе "Java", создана пользователем zeza, 17 мар 2014.

Статус темы:
Закрыта.
  1. zeza

    zeza New Member

    Репутация:
    0
    Регистрация:
    17 мар 2014
    Сообщения:
    1
    Симпатии:
    0
    дд,
    есть пример на Cscharp - его надо переделать на Java, пжлста, помогите (я новичок, кроме pl/sql ничего не знаю)
    Код:
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.Text;
    using System.Net;
    using System.Net.Security;
    using System.Globalization;
    using System.Security.Policy;
    using System.Security.Cryptography;
    using System.Security.Cryptography.X509Certificates;
    
    namespace uwcfs.sample
    {
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    string msg = "";
    
    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteCertificateValidationCB);
    
    msg += Environment.NewLine + " --- UMT --- " + Environment.NewLine + Environment.NewLine;
    
    msg += GetCurrencyList() + " - GetCurrencyList " + Environment.NewLine;
    msg += GetComission() + " - GetComission " + Environment.NewLine;
    
    MessageBox.Show(msg);
    }
    
    public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
    //For test, accept any certificate
    return true;
    }
    
    public static string GetCurrencyList()
    {
    string key = "nA{oYd;aFmewCZ=6(^CT3jsNtRT9Cq}gCVF0i0Yq.#0_3sh05ndK%1hkKpA@D6CI";
    
    MT.UMTSoapClient ws = new MT.UMTSoapClient();
    MT.UMTGetCurrencyListRequest request = new MT.UMTGetCurrencyListRequest();
    MT.Signature sign = new MT.Signature();
    MT.UMTGetCurrencyListResponse response;
    
    sign.MerchantCode = "FSTR";
    string hashData = key;
    sign.Sign = HASH.getHash512(hashData).ToUpper();
    
    response = ws.GetCurrencyList(request, sign);
    
    return (0 == response.Response.ErrorCode) ? "OK" + " (currencies: " + response.Currencies.Length.ToString() + ")" : "ERROR. " + response.Response.ErrorCode.ToString() + response.Response.ErrorMessage;
    //return (0 == response.Response.ErrorCode) ? "OK" : "ERROR";
    }
    
    public static string GetComission()
    {
    string key = "nA{oYd;aFmewCZ=6(^CT3jsNtRT9Cq}gCVF0i0Yq.#0_3sh05ndK%1hkKpA@D6CI";
    
    MT.UMTSoapClient ws = new MT.UMTSoapClient();
    MT.UMTGetComissionRequest request = new MT.MTGetComissionRequest();
    MT.Signature sign = new MT.Signature();
    MT.MTGetComissionResponse response;
    
    request.Amount = 100M;
    request.BankID = 673309;
    request.ComissionIncluded = 0;
    request.CurrencyCode = "USD";
    
    sign.MerchantCode = "FSTR";
    string hashData = request.BankID.ToString() + request.ComissionIncluded.ToString() + request.CurrencyCode + request.Amount.ToString() + request.UserID.ToString() + request.Discount + key;
    sign.Sign = HASH.getHash512(hashData).ToUpper();
    
    response = ws.GetComission(request, sign);
    
    return (0 == response.Response.ErrorCode) ? "OK" + " (comission: " + response.TransactionFee.ToString() + ")" : "ERROR. " + response.Response.ErrorCode.ToString() + response.Response.ErrorMessage;
    //return (0 == response.Response.ErrorCode) ? "OK" : "ERROR";
    }
    }
    
    public static class HASH
    {
    public static string getHash512(string data)
    {
    string hash = "";
    
    UTF8Encoding enc = new UTF8Encoding();
    SHA512Managed sha = new SHA512Managed();
    byte[] dataBytes = enc.GetBytes(data);
    byte[] hashBytes = sha.ComputeHash(dataBytes);
    
    foreach (byte b in hashBytes)
    {
    hash += String.Format("{0:x2}", b);
    }
    
    return hash;
    }
    }
    }
     
Загрузка...
Статус темы:
Закрыта.

Поделиться этой страницей