// GoPublicKey converts the provided Java PublicKey into Go PublicKey. func GoPublicKey(env jutil.Env, jKey jutil.Object) (security.PublicKey, error) { der, err := JavaPublicKeyToDER(env, jKey) if err != nil { return nil, err } return security.UnmarshalPublicKey(der) }
func (s *signer) PublicKey() security.PublicKey { env, freeFunc := jutil.GetEnv() defer freeFunc() publicKeySign := jutil.ClassSign("java.security.interfaces.ECPublicKey") jPublicKey, err := jutil.CallObjectMethod(env, s.jSigner, "publicKey", nil, publicKeySign) if err != nil { log.Printf("Couldn't get Java public key: %v", err) return nil } // Get the encoded version of the public key. encoded, err := jutil.CallByteArrayMethod(env, jPublicKey, "getEncoded", nil) if err != nil { log.Printf("Couldn't get encoded data for Java public key: %v", err) return nil } key, err := security.UnmarshalPublicKey(encoded) if err != nil { log.Printf("Couldn't parse Java ECDSA public key: " + err.Error()) return nil } return key }