2013-12-13 57 views
2

我嘗試登錄使用黑莓手機加密數據,但生成的簽名是沒有得到通過服務器端驗證(PHP)如何使用黑莓的加密

籤數據我想這一點 -

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()); 

請幫助

+0

什麼'cryptoSystem'和'keyPair'用於更改您的密碼?看起來你只是在創建重複的變量。 – Nate

回答

0

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); 
+0

感謝它的完美運作 – user2682882