Hepatitis B virus (HBV)-related hepatocellular carcinoma (HCC) misses the opportunity for surgery because it is not detected early. The molecular mechanism of hepatitis B-related liver cancer needs further understanding, and effective diagnostic and prognostic models are in urgent need. Expression profiles from the Cancer Genome Atlas (TCGA) Liver Hepatocellular Carcinoma (LIHC) and GSE121248, GSE94660, GSE76724 and GSE14520 from Gene Expression Omnibus (GEO) database were obtained. Differentially expressed genes (DEGs) between normal and tumor HBV-related HCC samples. Gene pairs are generated by comparing the expression levels of every two DEGs. The diagnostic signature of pairs of DEGs was built using cross-validation Lasso and Best Subset Selection regression. Hub genes and significant modules were screened by Cytoscape, and potential drugs were predicted by DGIdb. The gene-pair based prognostic signature was established by Cox proportional hazards regression model. xCell and ssGSEA were utilized to reveal the cell composition and cancer hallmarks to get an elucidation for the risk. A total of 457 DEGs were screened. A powerful diagnostic signature of two pairs of DEGs was built and validated in TCGA-LIHC and GEO datasets repeatedly with assured performance. Ten Hub genes were screened out. The prognostic signature of four gene pairs had good efficacy both in training and validation cohorts, with stromal score and several hallmarks related to the increasing of risk. Taken together, the study provided sight into the molecular mechanism as well as a novel strategy for the early diagnosis and prognosis for HBV-related HCC.