If you are a user of the tidyverse packages, particularly dplyr you could do the following...
library(dplyr)
#Create a named vector of old names, and new names.
name_vector <- A %>% pull(col1)
names(name_vector) <- A %>% pull(col2)
rename(B, all_of(name_vector))
The tidy selection all_of()
forces strictness when renaming. But depending on your exact use case and rigidity you could modify this.
Cheers