Home > Net >  Java PKCS8EncodedKeySpec signature into c # code?
Java PKCS8EncodedKeySpec signature into c # code?

Time:10-05

Test the haven't signed for success,
 
String keystr="private key";
Byte [] keybyte=HexBin. Decode (keystr);

PKCS8EncodedKeySpec PKCS8EncodedKeySpec=new PKCS8EncodedKeySpec (keybyte);
KeyFactory KeyFactory=KeyFactory. GetInstance (" EC ");
PrivateKey PrivateKey=keyFactory. GeneratePrivate (pkcs8EncodedKeySpec);
Signature Signature=Signature. GetInstance (" SHA1withECDSA ");
Signature. InitSign (privateKey);
Signature. The update (SRC) getBytes (" utf-8 "));
Byte [] arr=signature. Sign ();
Sign=HexBin. Encode (arr);

The above Java code needs to be converted into c # code, test for a long time didn't succeed,
Please help, thank you.

CodePudding user response:

The wrong information "SHA1withECDSA" is the signature algorithm

Key generation PKCS8EncodedKeySpec

So you into two-step, regardless of the algorithm first part, Mr Into key, and then to find the algorithm

PKCS8EncodedKeySpec look from the name is a PKCS # 8 format for RSA keys

So Google first "c # RSA PKCS # 8" (this with Google, baidu is difficult)

Below are the results
https://www.google.com/search? Ei=AzJvXfnnOsni - Ab5paP4Dw & amp; Q=C % 23 + RSA + PKCS % 238 & amp; Oq=C % 23 + RSA + PKCS % 238 & amp; Gs_l=psy - ab. 3... 478158.478158.. 479125... 0.0.. 0.0.0... 0... 2 j1.. GWS - wiz. 4 qhof1miymg & amp; Ved=0 ahukewi59bonn7bkahvjmd4khfnscp8q4dudcas & amp; Uact=5


Then find "SHA1withECDSA" algorithm, this is part of a RSA algorithm is a kind of

So, find the following things
https://blog.csdn.net/kevin860/article/details/82323116

Ps: don't want to keep looking, do you know the key information, I think you can find all your information

CodePudding user response:

Ecdsa can refer to, looked like is there a difference in this article

CodePudding user response:

Incidentally, basically has a received data in the same place
BouncyCastle

So he went to a check on the nuget
https://www.nuget.org/packages/BouncyCastle/

Find the official instructions look a the
Reference
Signature algorithms supported by SignerUtilities: MD2withRSA, MD4withRSA, MD5withRSA, RIPEMD128withRSA, RIPEMD160withECDSA, RIPEMD160withRSA, RIPEMD256withRSA, SHA - 1 withrsa, SHA - 224 withrsa, SHA - 256 withrsaandmgf1, SHA - 384 withrsaandmgf1, SHA - 512 withrsaandmgf1, SHA - 1 withdsa, and SHA - 1 withecdsa.


withecdsa SHA - 1

Combined with the above posts, almost certainly use the thing, can be done

CodePudding user response:

Thank you, I really see

CodePudding user response:

Thank you, I was watching

CodePudding user response:

Fw 4.7.2 encryption or 4.8 officially support the other way, see the MSDN can also be done, but the general compulsory + 4.7 version of the unit is not much, upstairs to the third party components method is more flexible, version limit is small,

CodePudding user response:

Tested or not, and then directly call the jar package to successful signature, estimates that problem on byte, byte is signed in Java, c # the byte is not signed

CodePudding user response:

Estimation problem on byte, byte is signed in Java, c # the byte is not signed, exchange need sbyte.

 
For (int I=0; i {
HexNumberTable [I]=1;
}

In the Java byte the default value is 1;
In c # in the signature received value is byte [] rather than sbyte [].
Caused more than byte has been submitted to the minimum value of the error,


  •  Tags:  
  • C#
  • Related