Documentation
¶
Overview ¶
Package dsa provides DSA digital signature cryptography.
Deprecated ¶
DSA is a legacy algorithm and should not be used for new applications. Use Ed25519 (crypto/ed25519) or ECDSA (crypto/ecdsa) instead. DSA keys with 1024-bit moduli are cryptographically weak.
This package is maintained only for compatibility with legacy systems.
Features ¶
- DSA key pair generation (L1024N160, L2048N224, L2048N256, L3072N256)
- Digital signature creation and verification
- PEM format support
Migration Recommendation ¶
// Instead of DSA:
import "github.com/common-library/go/security/crypto/ed25519"
keyPair := &ed25519.KeyPair{}
keyPair.Generate()
Package dsa provides dsa crypto related implementations.
Deprecated: DSA is a legacy algorithm and should not be used for new applications. Use Ed25519 (crypto/ed25519) or other modern alternatives instead. DSA keys with 1024-bit moduli are cryptographically weak.
Package dsa provides dsa crypto related implementations.
Deprecated: DSA is a legacy algorithm and should not be used for new applications. Use Ed25519 (crypto/ed25519) or other modern alternatives instead. DSA keys with 1024-bit moduli are cryptographically weak.
Package dsa provides dsa crypto related implementations.
Deprecated: DSA is a legacy algorithm and should not be used for new applications. Use Ed25519 (crypto/ed25519) or other modern alternatives instead. DSA keys with 1024-bit moduli are cryptographically weak.
Index ¶
- type KeyPairdeprecated
- func (kp *KeyPair) Generate(parameterSizes dsa.ParameterSizes) errordeprecated
- func (kp *KeyPair) GetKeyPair() (privateKey PrivateKey, publicKey PublicKey)deprecated
- func (kp *KeyPair) SetKeyPair(privateKey PrivateKey, publicKey PublicKey)deprecated
- func (kp *KeyPair) Sign(message string) (Signature, error)deprecated
- func (kp *KeyPair) Verify(message string, signature Signature) booldeprecated
- type PrivateKey
- func (pk *PrivateKey) Get() *dsa.PrivateKeydeprecated
- func (pk *PrivateKey) GetPemAsn1() (string, error)deprecated
- func (pk *PrivateKey) GetPublicKey() PublicKeydeprecated
- func (pk *PrivateKey) Set(privateKey *dsa.PrivateKey)deprecated
- func (pk *PrivateKey) SetPemAsn1(pemAsn1 string) errordeprecated
- func (pk *PrivateKey) SetSizes(parameterSizes dsa.ParameterSizes) errordeprecated
- func (pk *PrivateKey) Sign(message string) (Signature, error)deprecated
- func (pk *PrivateKey) Verify(message string, signature Signature) booldeprecated
- type PublicKey
- func (pub *PublicKey) Get() dsa.PublicKeydeprecated
- func (pub *PublicKey) GetPemAsn1() (string, error)deprecated
- func (pub *PublicKey) GetSsh() (string, error)deprecated
- func (pub *PublicKey) GetSshPublicKey() (ssh.PublicKey, error)deprecated
- func (pub *PublicKey) Set(publicKey dsa.PublicKey)deprecated
- func (pub *PublicKey) SetPemAsn1(pemAsn1 string) errordeprecated
- func (pub *PublicKey) SetSsh(sshKey string) errordeprecated
- func (pub *PublicKey) SetSshPublicKey(publicKey ssh.PublicKey) errordeprecated
- func (pub *PublicKey) Verify(message string, signature Signature) booldeprecated
- type Signaturedeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyPair
deprecated
type KeyPair struct {
// contains filtered or unexported fields
}
KeyPair provides DSA key pair operations.
Deprecated: Use Ed25519 or ECDSA instead.
func (*KeyPair) Generate
deprecated
func (kp *KeyPair) Generate(parameterSizes dsa.ParameterSizes) error
Generate creates a new DSA key pair.
Deprecated: Use Ed25519 or ECDSA for new applications.
Parameters ¶
- parameterSizes: Key size (L1024N160, L2048N224, L2048N256, L3072N256)
Returns ¶
- error: Error if generation fails, nil on success
Examples ¶
keyPair := &dsa.KeyPair{}
err := keyPair.Generate(dsa.L2048N256)
func (*KeyPair) GetKeyPair
deprecated
func (kp *KeyPair) GetKeyPair() (privateKey PrivateKey, publicKey PublicKey)
GetKeyPair retrieves the private and public keys.
Deprecated: Use Ed25519 or ECDSA for new applications.
Returns ¶
- privateKey: DSA private key
- publicKey: DSA public key
Examples ¶
privateKey, publicKey := keyPair.GetKeyPair()
func (*KeyPair) SetKeyPair
deprecated
func (kp *KeyPair) SetKeyPair(privateKey PrivateKey, publicKey PublicKey)
SetKeyPair sets the private and public keys.
Deprecated: Use Ed25519 or ECDSA for new applications.
Parameters ¶
- privateKey: DSA private key
- publicKey: DSA public key
Examples ¶
keyPair.SetKeyPair(privateKey, publicKey)
func (*KeyPair) Sign
deprecated
Sign creates a digital signature for the message.
Deprecated: Use Ed25519 or ECDSA for new applications.
Parameters ¶
- message: Text message to sign
Returns ¶
- Signature: DSA signature (R and S components)
- error: Error if signing fails, nil on success
Examples ¶
signature, err := keyPair.Sign("message")
func (*KeyPair) Verify
deprecated
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey is struct that provides private key related methods.
func (*PrivateKey) Get
deprecated
func (pk *PrivateKey) Get() *dsa.PrivateKey
Get returns the underlying *dsa.PrivateKey.
Deprecated: DSA is cryptographically weak and should not be used.
This method provides direct access to the Go standard library dsa.PrivateKey.
Returns:
- *dsa.PrivateKey: The underlying private key
func (*PrivateKey) GetPemAsn1
deprecated
func (pk *PrivateKey) GetPemAsn1() (string, error)
GetPemAsn1 encodes the private key as a PEM-encoded ASN.1 string.
Deprecated: DSA is cryptographically weak and should not be used.
This method converts the DSA private key to PEM format using ASN.1 encoding.
Returns:
- string: PEM-encoded DSA private key
- error: Error if encoding fails
Behavior:
- Output format: "-----BEGIN DSA PRIVATE KEY-----\n...\n-----END DSA PRIVATE KEY-----"
Example:
// For legacy compatibility only pemString, err := privateKey.GetPemAsn1()
func (*PrivateKey) GetPublicKey
deprecated
func (pk *PrivateKey) GetPublicKey() PublicKey
GetPublicKey extracts the public key from the private key.
Deprecated: DSA is cryptographically weak and should not be used.
Every DSA private key contains the corresponding public key. This method creates a PublicKey instance containing the public key portion.
Returns:
- PublicKey: The corresponding public key
Example:
// For legacy compatibility only
privateKey := &dsa.PrivateKey{}
privateKey.SetSizes(dsa.L2048N256)
publicKey := privateKey.GetPublicKey()
func (*PrivateKey) Set
deprecated
func (pk *PrivateKey) Set(privateKey *dsa.PrivateKey)
Set assigns an existing *dsa.PrivateKey to this PrivateKey instance.
Deprecated: DSA is cryptographically weak and should not be used.
Parameters:
- privateKey: The dsa.PrivateKey to assign
func (*PrivateKey) SetPemAsn1
deprecated
func (pk *PrivateKey) SetPemAsn1(pemAsn1 string) error
SetPemAsn1 loads a private key from a PEM-encoded ASN.1 string.
Deprecated: DSA is cryptographically weak and should not be used.
This method decodes a PEM-encoded DSA private key and sets it as the current key.
Parameters:
- pemAsn1: PEM-encoded ASN.1 DSA private key string
Returns:
- error: Error if decoding fails
Example:
// For legacy compatibility only
pemData, _ := os.ReadFile("dsa_private.pem")
privateKey := &dsa.PrivateKey{}
err := privateKey.SetPemAsn1(string(pemData))
func (*PrivateKey) SetSizes
deprecated
func (pk *PrivateKey) SetSizes(parameterSizes dsa.ParameterSizes) error
SetSizes generates a new DSA private key with the specified parameter sizes.
Deprecated: DSA is cryptographically weak and should not be used. Use Ed25519 or ECDSA for new applications.
This method generates DSA parameters and a key pair. L1024N160 is weak and should never be used.
Parameters:
- parameterSizes: The L and N parameter sizes (L1024N160, L2048N224, L2048N256, L3072N256)
Returns:
- error: Error if key generation fails
Security Warning:
- L1024N160: Cryptographically broken, do not use
- L2048N256: Minimum for legacy compatibility
- L3072N256: Maximum DSA size, still deprecated
Example:
// For legacy compatibility only
privateKey := &dsa.PrivateKey{}
err := privateKey.SetSizes(dsa.L2048N256)
func (*PrivateKey) Sign
deprecated
func (pk *PrivateKey) Sign(message string) (Signature, error)
Sign creates a digital signature for the given message.
Deprecated: DSA is cryptographically weak and should not be used. Use Ed25519 or ECDSA for new applications.
This method generates a DSA signature using the private key. The message is automatically hashed with SHA-256 before signing.
Parameters:
- message: The string to sign
Returns:
- Signature: The signature containing R and S components
- error: Error if signing fails
Behavior:
- Message is hashed with SHA-256 automatically
- Uses cryptographically secure random number generator
- Vulnerable to weak RNG attacks (nonce reuse reveals private key)
Example:
// For legacy compatibility only
privateKey := &dsa.PrivateKey{}
privateKey.SetSizes(dsa.L2048N256)
signature, err := privateKey.Sign("legacy message")
func (*PrivateKey) Verify
deprecated
func (pk *PrivateKey) Verify(message string, signature Signature) bool
Verify verifies a digital signature against the message.
Deprecated: DSA is cryptographically weak and should not be used. Use Ed25519 or ECDSA for new applications.
This method verifies that a signature was created by the corresponding private key. The message is hashed with SHA-256 before verification.
Parameters:
- message: The original message that was signed
- signature: The signature to verify
Returns:
- bool: true if signature is valid, false otherwise
Example:
// For legacy compatibility only
valid := privateKey.Verify("legacy message", signature)
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is struct that provides public key related methods.
func (*PublicKey) Get
deprecated
func (*PublicKey) GetPemAsn1
deprecated
GetPemAsn1 encodes the public key as a PEM-encoded ASN.1 string.
Deprecated: DSA is cryptographically weak and should not be used.
This method converts the DSA public key to PEM format using ASN.1 encoding.
Returns:
- string: PEM-encoded DSA public key
- error: Error if encoding fails
Example:
// For legacy compatibility only pemString, err := publicKey.GetPemAsn1()
func (*PublicKey) GetSsh
deprecated
GetSsh encodes the public key as an SSH authorized_keys format string.
Deprecated: DSA is cryptographically weak and should not be used. Modern SSH implementations are removing DSA support.
This method converts the DSA public key to SSH format.
Returns:
- string: SSH authorized_keys format string
- error: Error if encoding fails
Example:
// For legacy compatibility only sshKey, err := publicKey.GetSsh()
func (*PublicKey) GetSshPublicKey
deprecated
GetSshPublicKey converts the public key to an ssh.PublicKey.
Deprecated: DSA is cryptographically weak and should not be used.
Returns:
- ssh.PublicKey: The SSH public key instance
- error: Error if conversion fails
Example:
// For legacy compatibility only sshPubKey, err := publicKey.GetSshPublicKey()
func (*PublicKey) SetPemAsn1
deprecated
SetPemAsn1 loads a public key from a PEM-encoded ASN.1 string.
Deprecated: DSA is cryptographically weak and should not be used.
This method decodes a PEM-encoded DSA public key and sets it as the current key.
Parameters:
- pemAsn1: PEM-encoded ASN.1 DSA public key string
Returns:
- error: Error if decoding fails
Example:
// For legacy compatibility only
pemData, _ := os.ReadFile("dsa_public.pem")
publicKey := &dsa.PublicKey{}
err := publicKey.SetPemAsn1(string(pemData))
func (*PublicKey) SetSsh
deprecated
SetSsh loads a public key from an SSH authorized_keys format string.
Deprecated: DSA is cryptographically weak and should not be used. Modern SSH implementations are removing DSA support.
Parameters:
- sshKey: SSH authorized_keys format string
Returns:
- error: Error if parsing fails
Example:
// For legacy compatibility only
sshData, _ := os.ReadFile("id_dsa.pub")
publicKey := &dsa.PublicKey{}
err := publicKey.SetSsh(string(sshData))
func (*PublicKey) SetSshPublicKey
deprecated
SetSshPublicKey loads a public key from an ssh.PublicKey.
Deprecated: DSA is cryptographically weak and should not be used.
Parameters:
- publicKey: The ssh.PublicKey to convert
Returns:
- error: Error if conversion fails or key is not DSA
Example:
// For legacy compatibility only
sshPubKey, _ := ssh.ParsePublicKey(sshKeyBytes)
publicKey := &dsa.PublicKey{}
err := publicKey.SetSshPublicKey(sshPubKey)
func (*PublicKey) Verify
deprecated
Verify verifies a digital signature against the message.
Deprecated: DSA is cryptographically weak and should not be used. Use Ed25519 or ECDSA for new applications.
This method verifies that a signature was created by the corresponding private key. The message is hashed with SHA-256 before verification.
Parameters:
- message: The original message that was signed
- signature: The signature to verify
Returns:
- bool: true if signature is valid, false otherwise
Example:
// For legacy compatibility only
valid := publicKey.Verify("legacy message", signature)
type Signature
deprecated
Signature represents a DSA digital signature with R and S components.
Deprecated: DSA is cryptographically weak and should not be used.
A DSA signature consists of two large integers (R and S) that together prove the authenticity of a message. Both components are required for signature verification.
Security Warning:
- DSA signatures are vulnerable to weak random number generation
- Reusing the same random value (nonce) reveals the private key
- Use Ed25519 or ECDSA for new applications
Example:
// For legacy compatibility only
signature := dsa.Signature{
R: r, // First component
S: s, // Second component
}