Neos\Flow\Security\Cryptography\RsaWalletServicePhp::getFingerprintByPublicKey PHP Method

getFingerprintByPublicKey() public method

See for reference of OpenSSH "ssh-rsa" key format. The fingerprint is obtained by applying an MD5 hash on the raw public key bytes. If you have a PEM encoded private key, you can generate the same fingerprint using this: ssh-keygen -yf my-key.pem > my-key.pub ssh-keygen -lf my-key.pub
public getFingerprintByPublicKey ( string $publicKeyString ) : string
$publicKeyString string RSA public key, PKCS1 encoded
return string The public key fingerprint
    public function getFingerprintByPublicKey($publicKeyString)
    {
        $keyResource = openssl_pkey_get_public($publicKeyString);
        $keyDetails = openssl_pkey_get_details($keyResource);
        $modulus = $this->sshConvertMpint($keyDetails['rsa']['n']);
        $publicExponent = $this->sshConvertMpint($keyDetails['rsa']['e']);
        $rsaPublicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publicExponent), $publicExponent, strlen($modulus), $modulus);
        return md5($rsaPublicKey);
    }

Usage Example

    /**
     * @test
     */
    public function getFingerprintByPublicKeyCalculatesCorrectFingerprint()
    {
        $keyString = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDP7ZWzP/6x3SXyt0Al9UvyCe8D
TG6y1t7ovmWGw+D2x4BtZfbEHtNhlWHFkLLXzGKdgmzm4WjSB1fWQ1lfu5L8wY+g
HofCDIScx7AMgIB7hRB9ZMDEyWN/1vgSm8+4K4jUcD6OGLJYTSAlaQ7e2ZGaAY5h
p2P76gIh+wUlPjsr/QIDAQAB
-----END PUBLIC KEY-----';
        $this->assertEquals('cfa6879e3dfcf709db4cfd8e61fdd782', $this->rsaWalletService->getFingerprintByPublicKey($keyString));
    }