Question Convert Java to VB.Net

ThaKitti

New member
Joined
Mar 29, 2023
Messages
2
Programming Experience
1-3
I'm working on Certificate Private key. I have a sample source code in Java. Can anyone help convert to VB.Net?
Java:
public static String signSignatureMessage(String input, String filePath, String password, String alias) throws Exception {
    log.info("+signSignatureMessage(): Input[" +input+"], FilePath["+filePath+"]");
    String signMessage =null;
    char[] keypassword = password.toCharArray();

    KeyStorekeyStore = KeyStore.getInstance("PKCS12");     
    keyStore.load(new FileInputStream(filePath), keypassword);

    PrivateKey privKey = (PrivateKey)keyStore.getKey(alias, keypassword);       
    Signature rsa = Signature.getInstance("SHA512withRSA" );
    rsa.initSign(privKey,new SecureRandom());
    rsa.update(input.getBytes(SecurityWSConstants.ENCODING_UTF8));

    signMessage =new String(Base64.encode(rsa.sign()));

    // Remove eol
    signMessage = signMessage.replaceAll("","");
    log.info("-signSignatureMessage(): Result[" +signMessage+"]");
    return signMessage;
}
 
Last edited by a moderator:
As for the issue, you say "help" but it appears that you're hoping that we'll just do it for you. If you can show us what you've already done and explain where you're stuck, then we can help. Have you done any research on .NET types relevant to cryptography?
 
jmcilhinney Sorry, I'm new to this forum.

This is I try to convert and got struck to get SignMessage

VB.NET:
Dim sCertificate As X509Certificate2 = New X509Certificate2(My.Application.Info.DirectoryPath & "\" & sCertFile, sCertPswd, X509KeyStorageFlags.Exportable)
Dim wPrivateKey As RSACryptoServiceProvider = CType(sCertificate.PrivateKey, RSACryptoServiceProvider)
Dim sPrivateKey As RSACryptoServiceProvider = New RSACryptoServiceProvider()
sPrivateKey.ImportParameters(wPrivateKey.ExportParameters(True))
 
Back
Top