Gadgets

Monday, 18 February 2019

Drive Link

https://drive.google.com/open?id=1149_phRFvpNoKAoYFw3Uvl08RC_nrHI5

CMD:

cd C:\Users\NarendarReddy\Desktop\jni4net-0.8.8.0-bin\bin


.\proxygen.exe "C:\Users\NarendarReddy\source\repos\AuthenticatorDemo\AuthenticatorDemo\bin\Debug\AuthenticatorDemo.dll" -wd "C:\Users\NarendarReddy\eclipse-workspace\AuthTest"


cd C:\Users\NarendarReddy\eclipse-workspace\AuthTest



.\build.cmd


Java: 


package com.test;

import java.io.File;
import java.io.IOException;
import java.security.KeyStore;

import net.sf.jni4net.Bridge;

public class AuthTest {

public static void main(String[] args) {
try {

Bridge.setVerbose(true);
Bridge.init();
File file = new File("AuthenticatorDemo.j4n.dll");
Bridge.LoadAndRegisterAssemblyFrom(file);
System.out.println(authenticatordemo.AuthDemo.display());
System.out.println(authenticatordemo.AuthDemo.testing("Narendar"));
System.out.println(authenticatordemo.AuthDemo.UploadString("0a8cc33cf59da5b9df69df8cfdcf42b795738adffc428ece54f001b8090ba0dd", "PUGALIA RAJKUMAR NARAYANDAS"));

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}


C#:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


using System.Runtime.InteropServices.ComTypes;

using System.Security.Cryptography.Pkcs;

using System.Security.Cryptography;

using System.Security.Cryptography.X509Certificates;

using System.IO;

using System.Xml;

using System.Xml.Linq;

using System.Security;

using System.Security.Permissions;

namespace AuthenticatorDemo
{
    public class AuthDemo
    {
       
        public static string UploadString(String dataStr, String certName)

        {
            Console.WriteLine("dataStr : " + dataStr);
            Console.WriteLine("certName : " + certName);
           
            ContentInfo contentInfo = new ContentInfo(new System.Text.UTF8Encoding().GetBytes(dataStr));
            Console.WriteLine("contentInfo : " + contentInfo);
            SignedCms cms = new SignedCms(contentInfo);
            Console.WriteLine("cms : " + cms);
            /////////

            X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);
            Console.WriteLine("store : " + store);
           
            X509Certificate2Collection store2Coll = (X509Certificate2Collection)store.Certificates;
            foreach (var cert in store2Coll)
            {
                Console.WriteLine(cert);
            }
            System.Security.Cryptography.X509Certificates.X509Certificate2 rrr = null;
            Console.WriteLine("rrr : " + rrr);
            try

            {

                //store.Open(OpenFlags.ReadOnly);

                // Place all certificates in an X509Certificate2Collection object.
             
                X509Certificate2Collection signingCert = store2Coll.Find(X509FindType.FindBySubjectName, certName, true);
                Console.WriteLine("signingCert : " + signingCert.Count);
                if (signingCert.Count == 0)

                    rrr = null;

                // Return the first certificate in the collection, has the right name and is current.

                rrr = signingCert[0];
                Console.WriteLine("signingCert[0] : " + signingCert[0]);
            }

            finally

            {

                store.Close();

            }
            Console.WriteLine("rrrrrrr" + rrr);
            CmsSigner signer = new CmsSigner(rrr);
            Console.WriteLine("signer" + signer);
            cms.ComputeSignature(signer, false);
            Console.WriteLine("cms compute " + cms);
            byte[] pkcs7 = cms.Encode();
            Console.WriteLine("pkcs7 encode " + pkcs7);
            string str = Convert.ToBase64String(pkcs7);
            Console.WriteLine("strBase64" + str);
            return str;

        }

        public static string display()
        {
            return "Authentication Testingww";
        }

        public static string testing(String name)
        {
            return name = "Please execute";
        }
    }
}