|
|
@ -3,6 +3,7 @@ |
|
|
|
package crypto |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"crypto" |
|
|
|
"crypto/rand" |
|
|
|
"crypto/rsa" |
|
|
@ -63,7 +64,21 @@ func (pk *RsaPublicKey) Raw() ([]byte, error) { |
|
|
|
|
|
|
|
// Equals checks whether this key is equal to another
|
|
|
|
func (pk *RsaPublicKey) Equals(k Key) bool { |
|
|
|
return KeyEqual(pk, k) |
|
|
|
// make sure this is an rsa public key
|
|
|
|
other, ok := (k).(*RsaPublicKey) |
|
|
|
if !ok { |
|
|
|
a, err := pk.Raw() |
|
|
|
if err != nil { |
|
|
|
return false |
|
|
|
} |
|
|
|
b, err := k.Raw() |
|
|
|
if err != nil { |
|
|
|
return false |
|
|
|
} |
|
|
|
return bytes.Equal(a, b) |
|
|
|
} |
|
|
|
|
|
|
|
return pk.k.N.Cmp(other.k.N) == 0 && pk.k.E == other.k.E |
|
|
|
} |
|
|
|
|
|
|
|
// Sign returns a signature of the input data
|
|
|
@ -93,7 +108,35 @@ func (sk *RsaPrivateKey) Raw() ([]byte, error) { |
|
|
|
|
|
|
|
// Equals checks whether this key is equal to another
|
|
|
|
func (sk *RsaPrivateKey) Equals(k Key) bool { |
|
|
|
return KeyEqual(sk, k) |
|
|
|
// make sure this is an rsa public key
|
|
|
|
other, ok := (k).(*RsaPrivateKey) |
|
|
|
if !ok { |
|
|
|
a, err := sk.Raw() |
|
|
|
if err != nil { |
|
|
|
return false |
|
|
|
} |
|
|
|
b, err := k.Raw() |
|
|
|
if err != nil { |
|
|
|
return false |
|
|
|
} |
|
|
|
return bytes.Equal(a, b) |
|
|
|
} |
|
|
|
|
|
|
|
a := sk.sk |
|
|
|
b := other.sk |
|
|
|
|
|
|
|
if a.PublicKey.N.Cmp(b.PublicKey.N) != 0 { |
|
|
|
return false |
|
|
|
} |
|
|
|
if a.PublicKey.E != b.PublicKey.E { |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
if a.D.Cmp(b.D) != 0 { |
|
|
|
return false |
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
} |
|
|
|
|
|
|
|
// UnmarshalRsaPrivateKey returns a private key from the input x509 bytes
|
|
|
|