Signs the message with the private key.

@param message
The message to be signed.
@return The signature.
@throws EncryptionException
When it was not possible to sign the message.
553568
public String sign(final String message) throws EncryptionException {
      try {
         Signature sign = Signature.getInstance("SHA1withRSA");
         sign.initSign(privateKey);
         sign.update(message.getBytes(DEFAULT_CHARSET));

         return new String(Base64.encodeBase64(sign.sign()), DEFAULT_CHARSET);
      } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
         throw new EncryptionException("Unable to sign message: ", e);
      }
   }
551348
@Override
    public void sign ( byte[] data, int offset, int length, CommonServerMessageBlock request, CommonServerMessageBlock response ) {
        if ( log.isTraceEnabled() ) {
            log.trace("Signing with seq " + this.signSequence);
        }

        ( (ServerMessageBlock) request ).setSignSeq(this.signSequence);
        if ( response != null ) {
            ( (ServerMessageBlock) response ).setSignSeq(this.signSequence + 1);
        }

        try {
            update(this.macSigningKey, 0, this.macSigningKey.length);
            int index = offset + SmbConstants.SIGNATURE_OFFSET;
            for ( int i = 0; i < 8; i++ )
                data[ index + i ] = 0;
            SMBUtil.writeInt4(this.signSequence, data, index);
            update(data, offset, length);
            System.arraycopy(digest(), 0, data, index, 8);
            if ( this.bypass ) {
                this.bypass = false;
                System.arraycopy("BSRSPYL ".getBytes(), 0, data, index, 8);
            }
        }
        catch ( Exception ex ) {
            log.error("Signature failed", ex);
        }
        finally {
            if ( request instanceof SmbComNtCancel ) {
                this.signSequence++;
            }
            else {
                this.signSequence += 2;
            }
        }
    }
1118819
def sign(self, message, encoder=encoding.RawEncoder):
        
        raw_signed = libnacl.crypto_sign(message, self._signing_key)

        signature = encoder.encode(raw_signed[:libnacl.crypto_sign_BYTES])
        message = encoder.encode(raw_signed[libnacl.crypto_sign_BYTES:])
        signed = encoder.encode(raw_signed)

        return SignedMessage._from_parts(signature, message, signed)
1107900
public static byte[] signMessage(RSAPrivateKey key, byte[] message)
            throws InvalidKeyException, NoSuchAlgorithmException, SignatureException {
        return signMessage(key, message, DEFAULT_SIGNATURE_ALGORITHM);
    }
1130748
public static Sign sign(SignAlgorithm algorithm, byte[] privateKey, byte[] publicKey) {
		return new Sign(algorithm, privateKey, publicKey);
	}
256192
public byte[] sign(byte[] content,PrivateKey privateKey)  
    {  
        try   
        {  
            java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);  
            signature.initSign(privateKey);  
            signature.update(content);  
            return signature.sign();  
        }catch (Exception e)   
        {  
            log.error(e.getMessage(),e);
        }  
        return null;  
    }
359758
private static byte[] formatMessageForSigning(String message) {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES.length);
            bos.write(BITCOIN_SIGNED_MESSAGE_HEADER_BYTES);
            byte[] messageBytes = message.getBytes(StandardCharsets.UTF_8);
            VarInt size = new VarInt(messageBytes.length);
            bos.write(size.encode());
            bos.write(messageBytes);
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException(e);  // Cannot happen.
        }
    }
963505
public static String rsaSign(String content, String privateKey) {

        if (null == content || privateKey == null) {
            return null;
        }

        try {
            PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey, Base64.DEFAULT));
            KeyFactory keyf = KeyFactory.getInstance("RSA");
            PrivateKey priKey = keyf.generatePrivate(priPKCS8);
            java.security.Signature signature = java.security.Signature.getInstance(SIGN_ALGORITHMS);
            signature.initSign(priKey);
            signature.update(content.getBytes(CHARSET));
            byte[] signed = signature.sign();
            return Base64.encodeToString(signed, Base64.DEFAULT);
        } catch (Exception e) {
            //  这里是安全算法，为避免出现异常时泄露加密信息，这里不打印具体日志
            HMSAgentLog.e("rsaSign error");
        }

        return null;
    }
459112
private final void sign() throws Exception {
        String dataStr = this.getUserData().toString();
        byte[] data = Base64Coder.getBytes(dataStr);
        byte[] signature = sign(data, this.privateKey);
        this.setSignature(signature);
    }
1266561
public function sign($content, $privateKey)
    {
        try {
            return (new CryptoVirgilSigner($this->hashAlgorithm))->sign($content, $privateKey);
        } catch (Exception $exception) {
            throw new ContentSigningException($exception->getMessage(), $exception->getCode());
        }
    }
714929
def sign(message, gpg_home=None, gpg_signing_key=None, **config):
    

    if gpg_home is None or gpg_signing_key is None:
        raise ValueError("You must set the gpg_home \
                         and gpg_signing_key keyword arguments.")

    message['crypto'] = 'gpg'

    signature = _ctx.sign(
        fedmsg.encoding.dumps(message['msg']),
        gpg_signing_key,
        homedir=gpg_home
    )
    return dict(list(message.items()) + [('signature', b64encode(signature))])
494260
function (message, signature) {
      var md = forge.md.sha1.create();
      md.update(message, 'utf8');
      try {
        return this._cert.publicKey.verify(md.digest().bytes(), forge.util.decode64(signature));
      } catch (e) {
        return false;
      }
    }
770300
public byte[] sign(byte[] nonce) {
        try {
            char[] keyChars = this.readKeyChars();
            NKey nkey =  NKey.fromSeed(keyChars);
            byte[] sig = nkey.sign(nonce);
            nkey.clear();
            return sig;
        } catch (Exception exp) {
            throw new IllegalStateException("problem signing nonce", exp);
        }
    }
37382
public static ECKey signatureToKey(byte[] messageHash, String signatureBase64) throws SignatureException {
        final byte[] keyBytes = signatureToKeyBytes(messageHash, signatureBase64);
        return ECKey.fromPublicOnly(keyBytes);
    }
401797
def private_encrypt(key, message):
    '''
    
    '''
    if HAS_M2:
        return key.private_encrypt(message, salt.utils.rsax931.RSA_X931_PADDING)
    else:
        signer = salt.utils.rsax931.RSAX931Signer(key.exportKey('PEM'))
        return signer.sign(message)
271635
void signRequest(final RSAPublicKey rsaPublicKey, final byte[] data) throws IOException {
    // TODO (dxia) Support more than just Rsa keys
    final String keyType = Rsa.RSA_LABEL;
    final byte[] publicExponent = rsaPublicKey.getPublicExponent().toByteArray();
    final byte[] modulus = rsaPublicKey.getModulus().toByteArray();

    // Four bytes indicating length of string denoting key type
    // Four bytes indicating length of public exponent
    // Four bytes indicating length of modulus
    final int publicKeyLength = 4 + keyType.length()
                                + 4 + publicExponent.length
                                + 4 + modulus.length;

    // The message is made of:
    // Four bytes indicating length in bytes of rest of message
    // One byte indicating SSH2_AGENTC_SIGN_REQUEST
    // Four bytes denoting length of public key
    // Bytes representing the public key
    // Four bytes for length of data
    // Bytes representing data to be signed
    // Four bytes of flags
    final ByteBuffer buff = ByteBuffer.allocate(
        INT_BYTES + 1 + INT_BYTES + publicKeyLength + INT_BYTES + data.length + 4);

    // 13 =
    // One byte indicating SSH2_AGENTC_SIGN_REQUEST
    // Four bytes denoting length of public key
    // Four bytes for length of data
    // Four bytes of flags
    buff.putInt(publicKeyLength + data.length + 13);
    buff.put((byte) SSH2_AGENTC_SIGN_REQUEST);

    // Add the public key
    buff.putInt(publicKeyLength);
    buff.putInt(keyType.length());
    for (final byte b : keyType.getBytes()) {
      buff.put(b);
    }
    buff.putInt(publicExponent.length);
    buff.put(publicExponent);
    buff.putInt(modulus.length);
    buff.put(modulus);

    // Add the data to be signed
    buff.putInt(data.length);
    buff.put(data);

    // Add empty flags
    buff.put(new byte[] {0, 0, 0, 0});

    out.write(buff.array());
    out.flush();

    log.debug("Sent SSH2_AGENTC_SIGN_REQUEST message to ssh-agent.");
  }
920181
@Override
    public Builder signWith(String algorithm, String key) throws KeyException {

        if (algorithm == null || algorithm.isEmpty() || !algorithm.equals(Constants.SIGNATURE_ALG_HS256)) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_ALGORITHM_ERR", new Object[] { algorithm, Constants.SIGNATURE_ALG_HS256 });
            throw new KeyException(err);
        }
        if (key == null || key.isEmpty()) {
            String err = Tr.formatMessage(tc, "JWT_INVALID_KEY_ERR", new Object[] { algorithm, key });
            throw new KeyException(err);
        }
        alg = algorithm;
        sharedKey = key;
        return this;
    }