English 中文(简体)
C#中核实在 Java签署的问题
原标题:Problem verifying in C# what was signed in Java (RSA)

我希望我能在这里得到一些帮助,以便我最终解决这一令人沮丧的问题。

他们用以下法签了字:

public static void main(String[] args) throws Exception {
    if (args.length < 2)
        printInfoAndExit();
    String cmd = args[0];
    Security.addProvider(new BouncyCastleProvider());
    Signature signature = Signature.getInstance("SHA1withRSA", "BC");
    if ("sign".equalsIgnoreCase(cmd)) {
        String pemFileName = args[1];
        String dataFileName = args[2];

        byte[] data = readFile(dataFileName);

        FileReader fr = new FileReader(new File(pemFileName));
        PEMReader pemReader = new PEMReader(fr);
        KeyPair keyPair = (KeyPair) pemReader.readObject();
        fr.close();

        signature.initSign(keyPair.getPrivate());
        signature.update(data);
        byte[] signatureBytes = signature.sign();

        writeFile(signatureBytes, dataFileName + ".signed");
        String encoded = Base64.encode(signatureBytes);
        writeFile(encoded.getBytes(), dataFileName + ".signed.base64");
    } else {
        printInfoAndExit();
    }
}

在我收到数据时,我有其公开钥匙,试图用以下C#代码核实:

public static bool Verify(String msg, String signature, String publicKey)
{
    RsaKeyParameters remotepubkey = GetRsaPublicKey(publicKey);

    ISigner signer = SignerUtilities.GetSigner("SHA1withRSA");

    signer.Init(false, remotepubkey);
    byte[] sigBytes = Convert.FromBase64String(signature);
    byte[] msgBytes = Encoding.Default.GetBytes(msg);
    signer.BlockUpdate(msgBytes, 0, msgBytes.Length);
    return signer.VerifySignature(sigBytes);
}

This is not working!! I can however verify the data with openssl: openssl dgst -sha1 -verify public_key.pem -signature data.txt.signed data.txt

问题是,我没有做这项工作?

<>光> 我对钥匙没有问题,即工作正确,但 j和net网如何与RSA合作有差别?

** 在这种特殊情况下,我必须做的是改变格特赛人。

ISigner signer = SignerUtilities.GetSigner("RSA");

难道有人能告诉我,与RSA和RSA有差别?

最佳回答

这个问题实际上在 Java一侧解决。 他们有一些问题。

问题回答

你可能会对你的信息数据产生一个令人不安的问题。 您将原始档案数据转换为单编码,并试图将其改成 raw。 视档案的编码而定,如果档案甚至全文照样,贵方圆形可能不同于实际档案内容。

从档案中读到原材料,而不是铺设。 你没有显示实际阅读档案数据的标准,但我假定你重新读成文本。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签