Pergunta

I am trying to sign data using Blackberry cryptography but generated signature is not getting verify by the server side(PHP)

I tried this -

    RSACryptoSystem rsaCryptoSystem = new RSACryptoSystem(1024);
    // Create an RSA key pair.
     RSAKeyPair rsaKeyPair = new RSAKeyPair( rsaCryptoSystem );

    // Create the necessary RSA key pair for signing and verifying.
    RSACryptoSystem cryptoSystem = new RSACryptoSystem(1024);
    RSAKeyPair keyPair = new RSAKeyPair( cryptoSystem );

    // Create the digest and the salt value.
    SHA1Digest digest = new SHA1Digest();
    byte[] salt = RandomSource.getBytes( digest.getDigestLength() );

    // Create the RSASignatureSigner passing in a digest algorithm
    // and PSS signature formatter.
    PSSSignatureSigner signer =
             new PSSSignatureSigner( rsaKeyPair.getRSAPrivateKey(), digest, salt );

    signer.update( stringToSign.getBytes() );

    // Encode the signature using X509.
    EncodedSignature encSignature = SignatureEncoder.encode( signer,"X509" );
    String signedIdentifier = Base64.encode(encSignature.getEncodedSignature());

Please help

Foi útil?

Solução

Change your code with

byte[] dataBytes = stringToSign.getBytes();
   PKCS1SignatureSigner signer = new PKCS1SignatureSigner(rsaKeyPair.getRSAPrivateKey());

   signer.update(dataBytes, 0, dataBytes.length);
   byte[] signatureBytes = new byte[signer.getLength()];
   signer.sign(signatureBytes, 0);
   String signedIdentifier = Base64.encode(signatureBytes);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top