» »

c# RSACryptoServiceProvider..SignData(data,"SHA1") kako v Javi?

c# RSACryptoServiceProvider..SignData(data,"SHA1") kako v Javi?

peterv6i ::

Pozdrav,
za potrebe nekega webservisa moram del xml-ja podpisati s certifikatom..
Imam metodo v c# vendar me zanima kako bi to izvedel v Javi

private string SignCertificate(string cn,string text)
        {
            string potpis = "";
            // Open certificate store of current user
            X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            my.Open(OpenFlags.ReadOnly);
            // Look for the certificate with specific subject
            RSACryptoServiceProvider csp = null;
            foreach (X509Certificate2 cert in my.Certificates)
            {
                if (cert.Subject.Contains(cn))
                {
                    if (cert.NotAfter < DateTime.Now || cert.NotBefore > DateTime.Now)
                    {
                        continue;
                    }
                    // retrieve private key
                    csp = (RSACryptoServiceProvider)cert.PrivateKey;
                    break;
                }
            }
            if (csp == null)
            {
                throw new Exception("Valid certificate was not found");
            }

            // Hash the data
            UTF8Encoding encoding = new UTF8Encoding();
            byte[] data = encoding.GetBytes(text);
            string hex = BitConverter.ToString(csp.SignData(data,"SHA1")); 
            potpis = hex.Replace("-", "");
            return potpis;
        }


Torej v Javi bi rad naložil certifikat xy.cer ko poženem kodo in s tem certifikatom podpisal nek String kot je to v zgornji metodi csp.SignData(data,"SHA1")

Ima kdo kakšen primer?


hvala in lp
Peter


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Davčne blagajne (strani: 1 2 3 424 25 26 27 )

Oddelek: Programiranje
1344331730 (71733) Macketina
»

E-račun

Oddelek: Programiranje
217441 (4204) ivanhoe5x
»

[JAVA] HTTPS client

Oddelek: Programiranje
173169 (1899) peterv6i
»

[c#] Majhen problemček

Oddelek: Programiranje
10997 (805) darkolord
»

[C#] DateTime v bazo

Oddelek: Programiranje
51361 (1248) teac

Več podobnih tem