encode_string_base64 Subroutine

public subroutine encode_string_base64(str, output)

Encode a string as base64

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
character(len=256), intent(out) :: output

Source Code

  subroutine encode_string_base64(str, output)
    !! Encode a string as base64
    use iso_fortran_env, only: int8
    implicit none
    character(*), intent(in) :: str
    character(256), intent(out) :: output

    integer(int8), allocatable :: bytes(:)
    integer :: i, n

    n = len_trim(str)
    allocate(bytes(n))
    do i = 1, n
       bytes(i) = int(ichar(str(i:i)), int8)
    end do

    call base64_encode_bytes_fixed(bytes, n, output)
    deallocate(bytes)

  end subroutine encode_string_base64