<!--
{
  "availability" : [
    "iOS: 2.0.0 - 15.0.0",
    "iPadOS: 2.0.0 - 15.0.0",
    "macCatalyst: 13.1.0 - 15.0.0",
    "tvOS: 4.0.0 - 15.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 1.0.0 - 8.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecKeyRawSign(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecKeyRawSign"
  },
  "title" : "SecKeyRawSign(_:_:_:_:_:_:)"
}
-->

# SecKeyRawSign(_:_:_:_:_:_:)

Generates a digital signature for a block of data.

```
func SecKeyRawSign(_ key: SecKey, _ padding: SecPadding, _ dataToSign: UnsafePointer<UInt8>, _ dataToSignLen: Int, _ sig: UnsafeMutablePointer<UInt8>, _ sigLen: UnsafeMutablePointer<Int>) -> OSStatus
```

## Parameters

`key`

Private key with which to sign the data.

`padding`

The type of padding to use. Possible values are listed in [`SecPadding`](/documentation/Security/SecPadding). Use [`PKCS1SHA1`](/documentation/Security/SecPadding/PKCS1SHA1) if the data to be signed is a SHA1 digest of the actual data. If you specify [`kSecPaddingNone`](/documentation/Security/SecPadding/kSecPaddingNone), the data is signed as-is.

`dataToSign`

The data to be signed. Typically, a digest of the actual data is signed.

`dataToSignLen`

Length in bytes of the data in the `dataToSign` buffer. When PKCS1 padding is performed, the maximum length of data that can be signed is 11 bytes less than the value returned by the [`SecKeyGetBlockSize(_:)`](/documentation/Security/SecKeyGetBlockSize(_:)) function (`secKeyGetBlockSize() - 11`).

`sig`

On return, the digital signature.

`sigLen`

On entry, the size of the buffer provided in the `sig` parameter. On return, the amount of data actually placed in the buffer.

## Return Value

A result code. See [Security Framework Result Codes](/documentation/Security/security-framework-result-codes).

## Discussion

The behavior this function with [`kSecPaddingNone`](/documentation/Security/SecPadding/kSecPaddingNone) is undefined if the first byte of the data to sign is `0`; there is no way to verify leading zeroes, as they are discarded during the calculation.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)